i’d like to know the rule of thumb for do shell scrip
lets say i wanted to do something like this:
do shell script "ls ~"
display dialog WhatShellScriptReturned
how do i output everything that LS returns to a particular variable
p.s. This isn’t exactly what i want to do but i want to understand the concept behind it, if its easier show me an example with
echo 'helloWorld'
thanks
I can’t help you with a direct answer, but I do recall a longish thread here where the problems associated with having a shell script pass information back to an AppleScript were discussed. I don’t recall that the solution was straight-forward, either. “do shell script” is normally used for issuing commands that don’t reply or that, like curl, send the html data to your default browser for example. You can “tell application ‘Terminal’” to do your “ls” from an AppleScript and see the result there.
Works as well for
do shell script "echo "hello world""
as long as you escape the internal quotes. I have clearly mis-remembered (or misunderstood) the hoo ha about passing info from a shell script to an AppleScript.
Thanks Exactly what i wanted
You’re probably thinking of osascript, the command-line tool for invoking AppleScripts (rather than ‘do shell script’, the AppleScript tool for invoking shell scripts).
osascript currently can’t easily pass parameters to your script. There are skanky hacks which can get you there but they’re poor substitutes for a good osascript command.
That was indeed it. Now I remember the problem more clearly and agree with “shanky hacks”. I decided not to go there.
I’ve tried a few ways to do something that used to be easier before Ventura…running a shell script that uses a file and writes it. Now I get -
running code:
or
runs fine directly in Terminal.
I gave full disk access to script debugger.
Any suggestions?
I don’t think this code snippet could ever work as it is not formatted correctly.
First, is myShell.sh in a directory that is part of the PATH shell variable?
Otherwise you would need to put the full path to it.
Second, Quoted form of inFile is being sent as actual text because of the missing quote
should be
Third, you have an ending quote that should not be there
should be
Your right. In my haste to post the code and simplifying I failed to check the details. I still receive the same error and had it correct in my actual script. I believe I have narrowed it to the fact that I am triggering a shell script from AppleScript in Ventura/OS 13 and that it is reading a file and performing some complicated imagemagick commands and specifying the outFile. It worked fine in all previous OS versions and can be run directly from terminal in bash or zsh.
I have given execute permissions to the shell script and given script debugger access to full drive.
The shell script successfully creates a folder in the /tmp directory but does not have permission to read the file in the given path inFile and I am assuming will not be allowed to write the outFile.
The inFile posix path is /users/username/Desktop/somefolder/somefile.png
Any thoughts on this? I was sure it was a Ventura issue a script executing bash script but now uncertain why it would allow a folder to be created in /tmp if it will not allow reading a file.
Problem solved…
a few items had to change:
-
moving the Shell Script to my user directory solved it the permission issue when running from script debugger app. I guess until I sign the bundle which I usually do when export read only, the permissions may not work even though the shell script had execute permission. Seems similar to library permission issues.
-
I was using “.” as the temp directory and Ventura wouldn’t allow so I used “/tmp”
-
Another issue not encountered prior to Ventura was inside the shell script I used convert and magick commands to manipulate the image file and were “not found”. I updated the commands to be exact paths to the binary files to: /usr/local/bin/magick & /usr/local/bin/convert. (M1/M2 installs would be a different path which can be found using Whereis magick in terminal).
Hopefully this will help someone in future.