Sunday, March 26, 2017

#1 2005-10-13 02:42:51 pm

julifos
Administrator
From: MalasaƱa, Madrid
Registered: 2002-11-20
Posts: 2014

How can I execute multiple shell commands?

Let's say you have this code:

Applescript:

cd ~/Desktop
curl http://www.macscripter.net/ -o ms.html
cat ms.html >> AllMS.html

Simply use semicolons:

Applescript:

do shell script "cd ~/Desktop; curl http://www.macscripter.net/ -o ms.html; cat ms.html >> AllMS.html"

If you are working with a code more complex or pretty long, you can write it to an external file and run it from a do shell script statement. Eg:

Applescript:

set shellScript to "#!/bin/sh

if test -f ~/Desktop/ms.html; then
   echo 'Groovy!'
else
   echo 'Wait!'
fi"


set execFile to (open for access ("/tmp/sample" as POSIX file) with write permission)
write shellScript to execFile
close access execFile

do shell script "chmod 755 /tmp/sample; /tmp/sample | sh"

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.062 seconds, 12 queries executed ]

RSS (new topics) RSS (active topics)