Jump to content

AppleScript runs correctly in terminal but not through Alfred


Recommended Posts

Posted (edited)
Hi folks, I'm pretty new to Alfred. I want to make my first workflow but I encountered some issues.
I have replicated this issue under a minimal setup. This workflow only activates on input keyword "pclip", and triggers an AppScript that activates the "Preview" app.
The script is an "External Script". I tested the AppleScript in terminal and it successfully opens "Preview".
The script is located at `Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.F456C3BE-34D3-4CC4-8BD3-A2FC01F44022`.

The script looks like this:

image.thumb.png.e05ddaaffb443d5a62f2046cfc0f0030.png

 

The problem: when running this workflow through the keyword 'pclip', nothing happens. The debugger shows something, but my script log isn't in debugger output. 

 

image.thumb.png.c7a09a441bdc021f9c4b06fd1959f02e.png

 

Also, I found that the first time I launch it in a while Alfred shows a popup saying "Task '/Users/patrickmao/repos/alfred/pclip.applescript' failed with reason 'Couldn't posix_spawn: error 8'". I made sure I do `sudo chmod +x pclip.applescript, but that doesn't seem to help.

image.thumb.png.bef4d45c1fe148105655f1e1f44cfd26.png

 

Interestingly, the script does work correctly if I select "/usr/bin/osascript (AppleScript)" as Language instead of "External Script". So I suspect the issue is maybe related to permissions. What other permissions or setup does Alfred need other than +x for all users/groups?

 

Github link of this workflow.

 

Thanks in advance for your insights!

Edited by Padoriku
Posted

sudo is for elevating permissions, you shouldn’t use it for this case.

 

The problem is that you’re missing a shebang at the top of the script, specifically #!/usr/bin/osascript. Otherwise macOS doesn’t know how to execute the file. It also wouldn’t work in a Terminal if you just gave it the path to your script, which means you’re likely to be doing /usr/bin/osascript /path/to/script which is the same as selecting the language in Alfred. Either you need a shebang or to define the interpreter to run the file, that is true both inside and outside Alfred.


When sharing a workflow in the future, please share the exported file as opposed to the files inside. The goal is that we should be able to download it and install it easily to be able to see your workflow and help you better.

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