Redirect the error output of an AppleScript called through Cmd

The next question (for background see Interpolate into an AppleScript called through Cmd).

When calling AppleScript from the shell, the redirection works as expected:

eben60@Macmini ~ % osascript -e 'POSIX path of (choose folder with prompt "Pick a folder:")'             
2024-12-13 22:29:28.938 osascript[92280:10059569] +[IMKClient subclass]: chose IMKClient_Modern
/Users/eben60/Downloads/2023/

Without redirection: the line starting with 2024-12-13 is “log noise”, the third line is the directory selected.

eben60@Macmini ~ % osascript -e 'POSIX path of (choose folder with prompt "Pick a folder:")'  2> /dev/null
/Users/eben60/Downloads/2023/

With redirection: the error/warning/log message disappears in /dev/null as expected.


Now the same from Julia shell:

julia> script12 = """POSIX path of (choose folder with prompt "Pick a folder:")""";

julia> r12 = readchomp(`osascript -e $script12 2\> /dev/null`); # dialog opens
2024-12-13 22:39:12.192 osascript[92481:10066803] +[IMKClient subclass]: chose IMKClient_Modern

julia> r12
"/Users/eben60/Downloads/2023/"

Redirection ignored :frowning_face:

Redirection doesn’t work like that in Cmd literals. See the IO redirection section here:

2 Likes