Currently Being ModeratedMay 19, 2012 5:03 AM (in response to aarons510)
Making it two seprate files will be the easiest way.
Otherwise you're going to have to escape all special characters and if the shell script is more then a few lines it will be a pain and prone to errors.
Currently Being ModeratedMay 19, 2012 12:12 PM (in response to Frank Caggiano)
Since all but the first couple of lines are identical except for a few digits in a specific location, I only need to know precisely what special characters to escape and how. It should be easy for me to then change all the lines quickly in a text editor. The only potentially 'special' characters in each line are those that occur in every URL, plus HYPHEN and SPACE, if those are 'special'.
The other thing I need to know is what, exactly, encloses the totality of these lines.
Currently Being ModeratedMay 19, 2012 2:05 PM (in response to aarons510)
The shell script permissions should stay the same, so it would be executable on another system. If it needs to run with elevated access, it would probably be easier to use an AppleScript to get authentication.
Another option would be to create a script application and include the shell script file in the bundle's Resources folder. From there, the path to the shell script can be fetched by using Standard Additions' path to resource command, where it can be used in AppleScript's do shell script command. Note that the shell script will just have a default shell, so you can't rely on any environment variables such as $PATH, and will therefore need to use its full path.
Currently Being ModeratedMay 19, 2012 3:36 PM (in response to aarons510)
an example of writing a simple shell script into an applescript:
set ss to "cd ~/Downloads
echo 'This is a file list for the \"Downloads\" folder'
set dlf to do shell script ss
display alert dlf giving up after 10
The characters you'll need to escape are double-quotes and backslashes: use \" for literal doublequotes and \\ for literal backslashes. Everything else should be fine, though you'll make your life simpler by using single-quotes where you can.
as red_menace pointed out, this may run without any of the PATH or environment variables you expect to see in a terminal session. that's because do shell script doesn't run to bash_profile files the way Terminal.app does.
Currently Being ModeratedMay 21, 2012 1:22 AM (in response to red_menace)
This is something I will try sooner or later, since I may want to send more complex shell scripts in the future. Some immediate questions, though.
1) Can you point me to examples of how to do what you are suggesting?
2) Can I specify a particular shell? WIll the default shell be the same, presumably bash, for everybody? What if I want to use a shell I'm more familiar with, like csh or tcsh?
Currently Being ModeratedMay 21, 2012 1:33 AM (in response to twtwtw)
So it's basically a matter of setting the value of a variable to the lines of the shell script? It also appears that line breaks don't have to be escaped, which is good.
Presumably, if I need a PATH to be defined, I can do it at the start of the script. Or I can just use the full path for every program to be invoked.
I don't know what the display alert command does, but I can presumably look it up for myself. I am now too tired to think, so I'll come back very soon.
Currently Being ModeratedMay 21, 2012 6:58 AM (in response to aarons510)
While it is possible to do this in the Applescript if the shell script gets at all complicated escaping characters and debugging will be much harder then it needs to be.
For example taking twtwtw's example and just adding one Applescript variable gives:
set dir to POSIX path of (choose folder)
set ss to "cd " & dir & "
echo 'This is a file list for the \"" & dir & "\" folder'
set dlf to do shell script ss
display alert dlf giving up after 10
Twtwtw's suggestion of creating an Applescript application bundle is, I believe, the best way to go. You can keep the shell script and Applescript separate making maintenance and debugging much simpler and your friend just gets one 'file' to install and run.
Currently Being ModeratedMay 21, 2012 7:28 AM (in response to aarons510)
You would create a script application something like:
set theCommand to POSIX path of (path to resource "myShellScript")
set theResult to (do shell script theCommand)
theResult --> standard output from the shell script, if any
Then place myShellScript (or whatever the name of your executable file is) in the Contents/Resources folder of the application bundle (right click on an application and "Show Package Contents" to open the bundle). The do shell script command always calls bash - see Technical Note TN2065 for more information.
Currently Being ModeratedMay 23, 2012 9:28 AM (in response to red_menace)
I'm rather confused by your use of four different colors in the 'something like' example you give. It appears that the words in blue, pink and purple are all meant to be used literally, while those in green, namely 'theCommand' and 'theResult', are variable names that can be changed arbitrarily?
BTW, I've always hated applescript becuse of its loose, pseudo-English syntax. I learned programming with Fortran66 and a couple of versions of Basic, with a bit of MAD, Algol, Comit, Snobol, and APL thrown in, mostly for fun. I wrote occasional C programs from the late 1970's into the 1990's, and many csh scripts over the last 30+ years. The only reason I'm resorting to applescript now is that I want to be able to write sometning that will be executable on a Tiger or Leopard system even by somebody who barely knows how to copy or move a file from one folder or volume to another.
Currently Being ModeratedMay 23, 2012 9:50 AM (in response to aarons510)
I just pasted code from the script editor - it's been a while since I've used the default settings, so my settings use blue for language keywords, purple for parameter names, green for variable names, and the pink color for scripting addition commands.
You can check AppleScript Editor > Preferences > Formatting for the particular color meanings in your editor.
Currently Being ModeratedJan 22, 2013 6:54 PM (in response to aarons510)
Saw this thread,which helped me.
But, I also had similar problem like aarons.
I followed red_menace suggestion and put the script directly in the Resources folder and not in the Scripts folder.
path to resource gave the resource not found error if the script was in Scripts folder.
Currently Being ModeratedJan 22, 2013 7:41 PM (in response to hary5366)
The path to resource command has an optional in directory parameter that can be used to get resources in subdirectories such as the Scripts folder - see the StandardAdditions scripting dictionary.