Jump to content

Best way to "Choose File" from inside a workflow?


Recommended Posts

I've got a workflow where at some point I want the user to select an image file from the disk. Right now, I'm using Run NSAppleScript (cached) for this.

on alfred_script(q)
  activate
  set p to "Select an image to process:"
  set theImage to choose file with prompt p of type {"public.image"}
  return (POSIX path of theImage) as text
end alfred_script

Is this "right" ? Is there a faster, better or more efficient way?

 

I ask because it feels "slow" when this step is triggered—much slower than native Alfred objects and File Navigation windows, not to mention that AppleScript seems to be going the way of the dodo.

 

So if there's a way to avoid it or speed it up I'd love to know.

 

Link to comment
17 hours ago, luckman212 said:

Right now, I'm using Run NSAppleScript (cached) for this.

 

Why the activate in the code?

 

17 hours ago, luckman212 said:

Is there a faster, better or more efficient way?

 

Use a File Action Trigger.

 

17 hours ago, luckman212 said:

AppleScript seems to be going the way of the dodo.

 

Based on what? I doubt Apple will either develop it further or fix existing bugs, but I see no evidence they’ll phase it out soon.

Link to comment
1 hour ago, vitor said:

Why the activate in the code?

 

Thanks @vitor ...

 

Without activate in there, the choose file dialog opens in without focusing itself, so an extra click is required to bring it to the front before it will accept input (at least on my system).

 

I also have a File Action trigger in my workflow, but that forces me to remember not to press [ENTER] when selecting the file and remember to use [CTRL] instead to trigger the File Actions. It's definitely faster when I can remember these sequences -- but...I often don't 😩

 

1 hour ago, vitor said:

I doubt Apple will either develop it further or fix existing bugs

 

...exactly why I try to avoid using it ! Anyway, for now it seems to be an ok tool for the job.

 

Link to comment
1 hour ago, luckman212 said:

but that forces me to remember not to press [ENTER] when selecting the file and remember to use [CTRL] instead to trigger the File Actions.

 

I find File Actions far more useful directly from Finder using whatever Selection Hotkey you have set in Alfred Preferences > Features > Actions > General.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...