Jump to content
elguapo

Permission Error on External AppleScript Script

Recommended Posts

Version: Alfred 3.4.1

 

I am new to Alfred and am running into a problem. I created an AppleScript to send information from Outlook 2016 to OmniFocus 2. I have it set to run an external script (makes it much easier for me to make changes and test). I created a hotkey to run the script. When I launch the script with the hotkey, I get this error:

Unable to run task!

Reason: launch path not accessible

The external script may not exist, or does not have execute (+x) permissions.

I have tried putting in the script folder for OmniFocus, Outlook and Alfred, but get the error each time. I am sure I a doing something simple wrong. Thanks in advance for your help!

Share this post


Link to post

Hi!

 

If you set the preference in Alfred to "Run AppleScripts instead of opening" (found in: "Alfred Preferences -> File Search -> Advanced -> AppleScripts [ ]  Run AppleScripts instead of opening), then when you search and open an AppleScript file in Alfred then Alfred will run it directly. So, no need to create a script for that. Just use a Hotkey trigger connected to an Open File action (where you can directly drag and drop the AppleScript that you want to run).

 

However, if you want to go with creating a script, then you would be better using a Bash script file that run the AppleScript file using the osascript command.

 

Example:

#!/bin/bash

osascript path/to/your/applescript/file.scpt

Also, before you'll be able to use it, you will need to make your Bash file executable using `chmod +x yourFile.sh`

 

Or instead of creating a Bash file, just use a "Run Script" action in Alfred set to Language "/bin/bash" and with the osascript command inside "osascript path/to/you/applescript/file.scpt" 

Edited by GuiB

Share this post


Link to post
1 hour ago, elguapo said:

does not have execute (+x) permissions

 

@GuiB gave some solutions, but didn't explain what the root cause of the problem is.

 

(Excuse me if this explanation comes across as for-idiots or patronising: I'm aiming to explain this just once and link to it in future, so I'm writing this for total noobs.)

 

macOS is basically a UNIX system with Cool Apple Shit layered on top.

 

Alfred itself exists in the Cool Apple Shit layer, but workflows are at the lower UNIX level. This means they must, essentially, be UNIX programs.

 

As such, an External Script element can only run a UNIX executable, which is to say something you can run from a shell.

 

Concretely, that means the execute bit must be set (run chmod +x /path/to/script in a shell), but also that it must be a UNIX program or a script with a shebang.

 

AppleScript, as the name implies, belongs to the higher Cool Apple Shit layer (though AppleScript is pretty damn far from cool), and as a result you can't run it directly via the UNIX subsystem.

 

Fortunately, Apple has written a bunch of programs to access the Cool Apple Shit from the underlying UNIX layer. As @GuiB explained, the one you need to run AppleScript scripts from the UNIX layer is osascript. But there are other super-cool ones, like security, which provides access to the macOS Keychain, and mdfind, which lets you run Spotlight queries from the command line/scripts/workflows.

 

 

Share this post


Link to post

@deanishe Making this comment since you mentioned you wanted to make the post clear for newbies and link to it in the future.

 

1 hour ago, deanishe said:

which is to say something you can run from a shell

 

I’d expand a bit more on that. For example: “which is to say something you can run from a shell (the command-line interface that the Terminal app uses to run commands)”.

 

1 hour ago, deanishe said:

program or a script with a shebang.

 

I’d link to an explanation of what a shebang is.

Edited by vitor

Share this post


Link to post

I deliberately left the "shebang" comment as an exercise for the reader (I didn't want to get into the details of UNIX scripting).

 

Now we've gone there, I guess we need to mention that Alfred runs your scripts in its own, empty environment, not your shell's. 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...