Applescript List Items & Lists In General

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Applescript List Items & Lists In General Tue Nov 20, 2018 3:19 am • by kvsche
Hello! First time poster long time lurker. I used the free trial of Hazel years ago - couldn't wrap my mind around it. I saw it's potential but it didn't really process or "stick" with me. Needless to say, I am back and bought it at few days ago. Thanks again for this great app / utility / service :D

Here's my problem - I have 5 file names:

    blue.bright.bubble.big
    burn.rot.red.reason
    yield.yolk.yard.yawn.yellow
    green.glow.garden.grass.gallop
    only.onyx.open.orange.oscar

I could sort these files in any number of ways but for convenience's sake, I'd like to say that I need them to be compared to a list. If they match the items on that list -> actions are run. So in (embedded) Applescript, I would make a list and say (essentially):

Code: Select all
set theList to {"red", "yellow", "green", "blue", "orange"}


I would then repeat through that list, returning each item to hazel for use later. I could also do my comparison directly in the embedded AppleScript and return "true" or "false". My problem is: is I'd like to keep my code as short as possible. I would also like to avoid doing my comparisons directly in the script itself.

Hopefully I'm not unclear, or am not blamed for reading something I should have (I scour the forums and constantly reread the user guide). So I apologize in advanced if I missed some answers related to these questions:

    1. Am I better off doing my comparisons in Applescript or let Hazel handle them?

    2. If I did want to return (individual) list items from (embedded) Applescript - do I need to add the variable list name or each specific item attribute I am exporting to the custom attributes window (right side)?

    3. Is it even worth my time to write out (embedded) Applescript lists if a potential update around the corner incorporates lists and list items?

    4. I am looking on potentially upgrading my Mac soon - I'd like the transition to be somewhat painless as far as backing up Hazel rules - then adding it to future Macs ensuring it works "out of the box" (so to speak). With this in mind, what can I do to help ease the transition considering questions 1-3?

(also, it's currently late where I am located. I apologize if my babble is incoherent)
kvsche
 
Posts: 2
Joined: Sat Nov 17, 2018 11:26 pm

There are no custom list types at the moment so it's probably best to do the comparison in the script, or use multiple conditions to match each one individually without AppleScript.

As for #4, make sure you keep backups via Time Machine or the backup software of your choice. You can also export your rules from Hazel though keep in mind that only preserves the rules and not the list of folders they belong to.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Applescript List Items & Lists In General Tue Nov 20, 2018 3:00 pm • by kvsche
Thanks for the quick response! I'm not currently in front of my computer - and I'm sure I know the answer to this already: but is there a way to write a script to export one attribute that repeats through a list of one item at a time? I am assuming that this is possible, and that I just haven't been writing the code appropriately.

Edit: Follow up question - if I were to backup ("Export All Rules") in hazel, will it included the embedded scripts?
kvsche
 
Posts: 2
Joined: Sat Nov 17, 2018 11:26 pm

I'm not sure how you would want such a script to work. The script runs once so I don't see how it can loop through multiple times, returning a new value.

And yes, if you export your rules, any embedded scripts will be stored with them.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron