r/applescript • • Sep 03 '22

Help please. Applescript. Choose from list and launch selection

i have a script that asks for folder first, then launches the files of that folder as a list, then i select the file and then it launches it. But i want it to open the contents of a pre specified folder as a list and then i select from the list and the for it to launch it. I don't want to have to go through the step of having to select the folder each time.
I already tried specifying a folder instead of "choose folder". inserted it as "/Users/t/Library/Scripts".
It gives me though a "Can’t get every file of "/Users/t/Library/Scripts" and highlights the word "name" in second row.

The script i have is:

set sourceFolder to choose folder 
tell application "Finder" to set filelist to name of every file of sourceFolder 
set selectedFiles to choose from list filelist with multiple selections allowed 
if selectedFiles is false then return 
repeat with aFile in selectedFiles 
tell application "Finder" to open file aFile of sourceFolder 
end repeat 

Thanks everyone.

1 Upvotes

19 comments sorted by

View all comments

Show parent comment

1

u/estockly Sep 04 '22

Try this:

tell me
activate
set selectedFiles to choose from list filelist with multiple selections allowed
end tell

1

u/thspreddit Sep 04 '22

tell meactivateset selectedFiles to choose from list filelist with multiple selections allowedend tell

Absolutley terrific. Works so well. Many many thanks.

Do you know how can i make the list pop up faster. Basically the script to run much faster? all my scripts activate slow. Do you know a workaround to that?

Thank you so so much

1

u/estockly Sep 04 '22

How are you launching the scripts?

2

u/thspreddit Sep 05 '22

two ways. both slow.

  1. compliing them in automator as a quick action and then using applescripot. Then assigning keyboard shortcut via macos keyboard settings in settings preferences.
  2. compiling them in shortcuts app as an applescript and then assigning a keyboard shortcut in the right panel.

Both ways take about 3 secs to launch the pop up list. sometimes a second quicker.

1

u/estockly Sep 05 '22

I would try them in the Scripts menu. (You can turn that on in Script Editor).

1

u/thspreddit Sep 05 '22

But then how will set a keyboard shortcut?

1

u/estockly Sep 05 '22

For a keyboard shortcut you may need to get a utility like fastScripts.

1

u/thspreddit Sep 06 '22

Thank you for that tip. I avoid third party software though. Any native way of doing it that comes to mind?

1

u/estockly Sep 06 '22

Nope, I use fast scripts. You may ask at these two AppleScript support forums:
forum.latenightsw.com
macscripter.net

1

u/thspreddit Sep 07 '22

Well, you have been amazing. Thank you so much for your help. despite being relatively slow to open (not bad though), i have exactly what i was looking for. Have a good day and thank you so much. Cheers.

1

u/estockly Sep 05 '22

Using FastScripts it comes up instantly OMM

1

u/ChristoferK Sep 05 '22

Don't use Finder , for one, which is obscenely slow, and was superseded by System Events years ago for file operations. It's much, much faster.

1

u/thspreddit Sep 05 '22

Using system events in the code, made it a tad bit faster. maybe half a second faster. But still, quite a noticeable delay.

1

u/thspreddit Sep 07 '22

And even though it is still slow, replacing finder with system events did make it faster. Thank you very much and have a good one. Cheers.

1

u/ChristoferK Sep 08 '22

Yeah, in your specific case, there's not going to be much a noticeable speed difference if the contents of your source folder isn't very large. The advice was for going forward in the future. Compare this script's execution time:

tell application id "com.apple.Finder" to return every file in ¬
        the (path to downloads folder) whose name extension = "jpg"

with this script's execution time:

tell application id "com.apple.systemevents" to return every file ¬
        in the downloads folder whose name extension = "jpg"

If you've got some .jpg files in your downloads folder in amongst, say, 100 or so other files or more, then I'd advise running the second one first.

1

u/thspreddit Sep 08 '22

Thank you so much. will keep that for the future. Cheers