Jump to content

[Solved] Output of Run Script (osascript) action terminates with line break


Recommended Posts

The Run Script action, particularly relevant to osascript, appears to return the result of the script as text that is terminated with a line break character.  This causes problems when the script returns a file path, which gets fed into the subsequent node of the workflow that is expecting to receive a file path that points to an existing file, but instead receives a file path that points to a non-existent file because of the extra character in its name.

 

https://transfer.sh/LEmG3/Bug Report.alfredworkflow

 

The workflow demonstrates the phenomenon.  It simply displays an osascript output surrounded by quotes to visualise the string in its entirety.

image.thumb.jpeg.659907ff341a921d84ff33ba4a3a093d.jpeg

 

 The code used in the `osascript` is:

        on run

                return "~/Downloads"

        end run

 

This might not technically be a bug, per se, as I'm guessing the Run Script actions all execute a script by way of a shell command, and therefore it may be that the osascript command itself is returning this output rather than something Alfred is doing.  That said, when I run the following command in Terminal:

 

osascript -e 'return "~/Downloads"' | wc -l

 

it reports that the output does only contain a single line.

Link to comment

@CJK Alfred doesn't process the output of a Run Script object in any way, and osascript non-optionally appends a newline to any output (which could be seen as an osascript bug, but I suspect this behaviour will never change).

 

You have a couple of options:

 

1. If you switched your script to bash, then use echo -n for output, you'll get the output as expected.

 

2. Add a Transform utility object after your Run Script set to trim the output. This will remove the newline from your osascript.

 

This has come up before, and my opinion remains that Alfred shouldn't automatically process the output of ant Run Script objects (e.g. to trim), as this would lead to more unexpected behaviour than not.

 

Cheers,

Andrew

 

[moving to workflow help].

Link to comment
  • Andrew changed the title to [Solved] Output of Run Script (osascript) action terminates with line break
  • Vero locked this topic
  • Andrew unlocked this topic

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