Jump to content

Test for Workflow Directory with Applescript

Recommended Posts

In Alfred v1, I could test for the location of an extension using Applescript (enclosing a 'do shell script "pwd"' command that returned the POSIX path of the actual location of the extension on the users disk). That required the Alfred v1 Background option to be checked to work.


The use case is to locate the extension/workflow on the disk to link/include additional resources like external .scpt files to be run, custom icon files to be displayed in Applescript dialogs, etc.


Now I'm trying to do the same thing with Alfred v2, but all I get is an "/" as POSIX path (which is the exact same behaviour as in v1 when the Background option was NOT checked).



Here's a sample/test extension for v1 which upon keyword "twd" displays an Applescript dialog with the POSIX path to the extension:


Test Extension Directory.alfredextension


(Try unchecking the Background option and you'll get an "/" only instead"



Here's a sample test workflow for v2 that tries to accomplish the exact same thing with Applescript but does return an "/" only either. In v2, there is nothing like a Background option for Applescript Workflow modules anymore. I suspect v2 runs an Applescript the exact way like v1 did when the Background option was unchecked (use "twd" to run):


Test Workflow Directory with Applescript.alfredworkflow




In v2 however using a shellscript module to do that works just fine (use "twdsh" to run):


Test Workflow Directory using sh.alfredworkflow



To include an extra shellscript module that only does a "pwd" to pass on to my Applescript to get the workflow path seems overkill, especially when additional queries need to be preserved.


I'd be truly grateful if you could point out if that's down to the yet incomplete Applescript support in v2 (? - Everything else Applescript runs just fine in v2 so far), if there'll be some option to get the "Background" behaviour back in v2 later on, or if there is another, simpler way to test for the actual full path to the workflow directory from inside an Applescript with v2.



Link to comment

+1 for getting this option.


I had a few goes of trying to run a shell script from AppleScript to return a non root path, but none of them returned anything other than "/".  So logically I can see why but just in case ... has anyone figured out a way (even a convoluted one) of getting the workflow path into an AppleScript?

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...