Same way you would do a shell one-liner. E.g.: if [ -e somefile] ; then sudo rm somefile; echo did it; fi
Keep in mind that 'do shell script' passes the argument to sh -c, or something to that effect - that do not understand newlines, as it is expecting everything all in one line. This actually is an each way to test it outside your script - if your command works when you pass it to sh -c, it will probably work in your applescript.
Furthermore, your 'cd' command is unnecessary, it would be better to just put the whole path in your 'sudo rm' command. And if sudo asks for a password, you'll be out of luck. A better solution might be: do shell script 'rm -f /Users/administrator/Desktop/sp.rtf' with administrator privileges This will pop an authentication dialog, and do the authentication (sudo) with the GUI, and not inside your script. You may well not be able to poke inside some other user's home directory anyway, so doing it all with admin permissions is likely necessary in any case.
Additionally, a point of terminology: there's no such thing as an "if-else loop". A loop is a for, foreach, while, or do-while construction, and it involves repetition. More standard terminology would be "if-statement" or "if-else statement". Yours is an if-statement, since there is no 'else'.
Hope this helps, -Dave On Apr 20, 2010, at 2:06 AM, spondita Madhuri Neog wrote:
Hi,
Can anyone help me as to how to embed a shellscript command containing an "if-else" loop into applescript.I know that "do shell script" can be used to call a shellscript command from applescript but I am not able to call multiple statements in the if-else block contained within the shellscript.
My if-else loop in the shellscript is as follows :
if [ -e /Users/administrator/Desktop/sp.rtf ]
then
cd /Users/administrator/Desktop
sudo rm sp.rtf
fi
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
|