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.



 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.

Share this post

Link to post

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





[moving to workflow help].

Share this post

Link to post

I just thought... it's worth adding that you do actually see the appended newline from osascript -e 'return "~/Downloads"' in Terminal. When using bash and echo -n, the next command is immediately after your output.




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.

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