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
5 (1)
Article Rating (1 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
Epoch & Unix Timestamp Conversion Tools
Viewed 33435 times since Fri, Jun 22, 2018
Managing temporary files with systemd-tmpfiles on Red Hat Enterprise Linux 7
Viewed 7847 times since Sun, Nov 22, 2020
How to manage Linux password expiry with the chage command
Viewed 10059 times since Tue, Sep 11, 2018
How To Create a Linux Swap File
Viewed 1379 times since Fri, Jun 8, 2018
Setting up encrypted tunnel using stunnel
Viewed 1332 times since Fri, Sep 28, 2018
SSH Essentials: Working with SSH Servers, Clients, and Keys
Viewed 2710 times since Wed, Jun 27, 2018
RHEL: Adding a boot entry to GRUB/GRUB2 configuration
Viewed 2207 times since Sun, May 27, 2018
10 nmap Commands Every Sysadmin Should Know
Viewed 7924 times since Wed, May 22, 2019
Set Up SSH Tunneling on a Linux / Unix / BSD Server To Bypass NAT
Viewed 10352 times since Fri, May 15, 2020
bash mistakes This page is a compilation of common mistakes made by bash users. Each example is flawed in some way.
Viewed 7514 times since Sun, Dec 6, 2020