Applescript: Run or Call a Shell Script

Applescript: Run or Call a Shell Script

last updated in Categories , ,

 

How do run a shell script with an AppleScript? How do I integrate shell scripts into AppleScript? How do I call a shell script called /path/to/chkhost.sh using an applescript?

AppleScript is a scripting for Mac OS. It is the Mac OS scripting interface, which is meant to operate in parallel with the graphical user interface. With AppleScript, you can control, and communicate among, applications, databases, networks, Web services, and even the operating system itself.

 

 

 

Running Shell Commands From AppleScript Scripts

You can easily execute shell commands from your AppleScript using the following syntax:

do shell script "command"
do shell script "command1; command2"
set variableName to do shell script "command"
set variableName to do shell script "command1; command2"
do shell script "/path/to/yourscript.sh"
do shell script "/bin/tcsh /path/to/yourscript.csh"
do shell script "/bin/tcsh -c  'command1'"

The following script statement uses a do shell script command to get list of the files from the current directory and store it into the AppleScript variable filesLists:

set filesLists to do shell script "ls"

Task: Pass an AppleScript Variable To Shell Command

Use the following syntax (h is an AppleScript variable which is passed to traceroute shell command):

set h  to "cyberciti.biz"
do shell script "traceroute " & h
5 (1)
Article Rating (1 Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
RHEL: Getting/Setting hardware clock’s time
Viewed 4179 times since Sat, Jun 2, 2018
How to schedule crontab in Unix Operating Systems
Viewed 2650 times since Fri, Jun 8, 2018
red hat 7 tmpfiles service
Viewed 2467 times since Thu, Oct 11, 2018
SYS: Configure a local repository. local repo
Viewed 11866 times since Mon, Oct 29, 2018
Linux - How to unlock and reset user’s account
Viewed 5901 times since Fri, Jun 8, 2018
Build a simple RPM that packages a single file
Viewed 9668 times since Sat, Jun 2, 2018
stunnel How To Encrypt Traffic to Redis with Stunnel on Ubuntu 16.04
Viewed 2936 times since Sun, Dec 6, 2020
Linux – How to check the exit status of several piped commands
Viewed 3632 times since Wed, Jul 25, 2018
How To: Create Self-Signed Certificate – OpenSSL
Viewed 3715 times since Mon, Feb 18, 2019
20 Practical Examples of RPM Commands in Linux rpm
Viewed 8926 times since Mon, Feb 18, 2019