Osascript stdin arguments


From man osascript:

Can someone tell me what “… you must explicitly specify '- for the script name.” means in number three.


I think it means “as a place holder to represent the script coming from standard input”:

do shell script "echo \"return 10 * 2\" | osascript -"
--> "20"

That’s ok. I had a brain lock. :smiley:

set t to quoted form of "on run argv
display dialog argv
end run"
do shell script "echo " & t & " | osascript - hello"

Edited: hi Nigel. Yes it looks like a placeholder. Without the minus sign, it thinks hello is a file.

Thanks anyway,

Mine was a bad example, as it works both with and without the “-”! The “-” must be used to represent a passed script to which you want to pass arguments.

Just in reply to the title of this topic because stdin can be used and arguments are something different.

stdin can be read using cat and osascript.

do shell script "echo 'data for stdin' | osascript -e 'tell application \"Finder\" to display dialog \"STDIN: \" & (do shell script \"cat\")'"

Hi DJ,

Is that faster than passing the arguments from (Edit) the arguments to osascript?

Edited: cat looked like it was pretty quick in your other script.


On the side, there is one other change that Apple made somewhere. ‘display dialog’ didn’t work before because it had no gui. It’s working now in Mavericks. I can’t remember if it worked before in Mountain Lion. Maybe they added System Events to the unix.

No, especially when passing multiple arguments:

do shell script "osascript -e 'on run argv
 set {arg1, arg2} to  argv
 tell application \"finder\"
 	display dialog \"first argument: \" & arg1 & return & \"second argument: \" & arg2
 end tell
end run' 'argument with spaces' argumentWithOutSpaces"

From the 10.9 release notes:

Wow, that’s great. they added it to osascript.

It looks as if osascript also runs Script Menu now.

-- Save as a compiled script in your scripts folder and run from Script Menu.
set myPath to (path to current application as text)
display dialog myPath