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/ 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/"
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 ""
do shell script "traceroute " & h
0 (0)
Article Rating (No Votes)
Rate this article
There are no attachments for this article.
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
How to Analyze or Read OS Watcher Output in three easy steps -- With Example ?
Viewed 5496 times since Thu, Jun 21, 2018
ZFS: Verify/change properties of a zfs filesystem
Viewed 984 times since Sun, Jun 3, 2018
Linux - How to monitor memory usage
Viewed 855 times since Fri, Jun 8, 2018
RHEL: Bonding network interfaces
Viewed 1435 times since Sat, Jun 2, 2018
how to list all hard disks in linux from command line
Viewed 835 times since Mon, Jan 28, 2019
Super Grub2 Disk
Viewed 1093 times since Wed, May 22, 2019
Linux - Cannot login from remote console but can access via ssh
Viewed 2281 times since Fri, Jun 8, 2018
How to use yum-cron to automatically update RHEL/CentOS Linux
Viewed 667 times since Wed, Oct 17, 2018
Nagrywanie sesji SSH do pliku
Viewed 1355 times since Thu, May 24, 2018
Linux Cluster Tutorial
Viewed 709 times since Sat, Sep 29, 2018