Jump to content

Running script filter with external script, 'Unable to run task!' error


Recommended Posts

I am trying to create a (very) simple JSON script filter that is run as an external script (so that it can be updated by another app). It works perfectly as an internal bash script but not externally.

 

The non-functioning workflow: [removed as no longer needed]

 

 1848217962_Screenshot2021-08-30at10_50_29.thumb.png.2c79ca6667d900d2f3bd8d607b0fc95f.png

 

The error message:

944390414_Screenshot2021-08-30at10_50_18.thumb.png.78e2ebfbef7c453856dc8c829b465a17.png

Alfred 4.5.1 [1256]

MacOS 10.15.7

 

I am guessing that the bash shebang (as has been discussed here) is incomplete, or I'm making some other mistake. I'm just not clear on what Alfred is doing with the script when run internally that it isn't doing when run externally (a newb issue, I'm sure).

 

Any help would be greatly appreciated.

 

 

Edited by p1r2c1
Link to comment
1 hour ago, p1r2c1 said:

I am guessing that the bash shebang (as has been discussed here) is incomplete, or I'm making some other mistake

 

Almost. The problem is exactly what Alfred suggests: you haven’t set the execute permission. You need to run chmod +x test.scpt in your shell to make the script executable.

 

Also, it’s not a good idea to name it test.scpt. .scpt is the file extension for compiled AppleScript scripts, not bash scripts. More appropriate names for a bash script would be test.sh, test.bash or just test.

 

1 hour ago, p1r2c1 said:

what Alfred is doing with the script when run internally that it isn't doing when run externally

 

What do you mean "run externally"?

 

In any case, this isn't something related to Alfred: your script is fundamentally not executable until you set the execute bit. That's just how UNIX systems work. You can't read a file if its read bit isn't set, you can't write to a file if its write bit isn't set, and you can't execute a file (or open a directory) if its execute bit isn't set.

Edited by deanishe
Link to comment

A fantastic reply, thank you very much. This is clearly something I should know but I would never have known where to look to find it out.

 

28 minutes ago, deanishe said:

What do you mean "run externally"?

 

I just meant 'when run on the basis of an external script' rather than one contained in Alfred. Perhaps a confusing way of putting it.

Link to comment

  

35 minutes ago, p1r2c1 said:

This is clearly something I should know but I would never have known where to look to find it out.

 

Should know is a bit strong unless you're a programmer. Alfred uses standard UNIX APIs to run scripts (ARGV for command-line arguments, environment variables, output on STDOUT, errors on STDERR). Googling for "shell scripting" would be a good start. It's not exactly the same thing, but most of the core concepts carry over.

 

35 minutes ago, p1r2c1 said:

I just meant 'when run on the basis of an external script' rather than one contained in Alfred.

 

Ah, right. I thought you meant outside Alfred.

 

Yeah, if you paste the code into the Script box, then Alfred takes care of creating the script file and making it executable for you. It's a better idea to use External Script where possible, though. It's faster, and the Script box is a very poor code editor.

Edited by deanishe
Link to comment
On 8/30/2021 at 2:38 PM, deanishe said:

Should know is a bit strong unless you're a programmer.

 

I may be too hard on myself!

 

In any case, I have run into another problem:

image.thumb.png.467a81235a9e72732a5007aedda7bb72.png

It also gives me "error 2" sometimes.

 

The workflow in question is generated from an AppleScript that gets a selected number of Keyboard Maestro macros and adds them to a JSON script filter. The JSON seems to be valid (JSON Editor opens it without a problem, and it is more fussy than Alfred). I've tried `chmod +x`, launched from the AppleScript and from Terminal. Also, the script won't run from the Alfred script box this time (the window appears but nothing drops down). I've put the script side by side with others that are still working for me and I can't see any meaningful difference.

 

https://www.dropbox.com/s/zz55r42jvyejwv6/__Script Filter test.alfredworkflow?dl=0

 

FWIW, tried this on both Catalina and Monterey.

 

There's probably something very simple that I'm missing again. Trying not to be too hard on myself! :)

Link to comment

 

9 hours ago, p1r2c1 said:

There's probably something very simple that I'm missing again.

 

Running the script in a shell, I get:

 

❯ ./test1234.sh
zsh: ./test1234.sh: bad interpreter: /bin/bash^M^Mcat: no such file or directory

 

^M means carriage return (CR). Those should be line feeds (LF). That is to say, you have the wrong end-of-line character. CR is the old MacOS 9 end-of-line character. macOS 10+ uses LF like all Unixes (Windows uses CRLF). Open the script in a proper code editor (TextMate is very good, and free) and change the script to use Unix line endings (LF).

Link to comment
1 hour ago, deanishe said:

^M means carriage return (CR). Those should be line feeds (LF). That is to say, you have the wrong end-of-line character. CR is the old MacOS 9 end-of-line character. macOS 10+ uses LF like all Unixes (Windows uses CRLF). Open the script in a proper code editor (TextMate is very good, and free) and change the script to use Unix line endings (LF).

 

Ah! Line endings. Those tricky little invisible gremlins. Again, this is something I should have figured out. Thanks @deanishe.

 

For anyone having this same problem, I found this helpful: http://www.apeth.com/sd5help/indexfolder/referencfolder/faqfolder/lineendings.html

Link to comment

Turning on "show invisible characters" is a very good idea when you're getting weird errors. People somehow manage to get all sorts of unwanted invisible characters in their scripts. That's also another reason to always provide your workflow, not just paste some code, when asking for assistance.

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