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
0 (0)
Article Rating (No 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
Terminal based "The Matrix" like implementation
Viewed 451 times since Thu, Apr 18, 2019
How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD find
Viewed 425 times since Mon, Oct 29, 2018
Cron YUM How to use yum-cron to automatically update RHEL/CentOS Linux
Viewed 418 times since Fri, Oct 26, 2018
RHCS6: Clustered LVM
Viewed 729 times since Sun, Jun 3, 2018
INSTALACJA MIB SNMP W SYSTEMIE CENTOS/RHEL 6
Viewed 578 times since Fri, Nov 30, 2018
A Simple Guide to Oracle Cluster File System (OCFS2) using iSCSI on Oracle Cloud Infrastructure
Viewed 1063 times since Sat, Jun 2, 2018
Netcat shell zabezpieczony hasłem
Viewed 783 times since Thu, May 24, 2018
RHEL: Change system’s hostname
Viewed 983 times since Sun, May 27, 2018
LVM: Mount LVM Partition(s) in Rescue Mode
Viewed 858 times since Sat, Jun 2, 2018
What is yum-cron ?
Viewed 1095 times since Fri, Oct 26, 2018