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
RHCS6: Clustered LVM
Viewed 2761 times since Sun, Jun 3, 2018
HowTo: Find Out Hard Disk Specs / Details on Linux
Viewed 4256 times since Mon, Jan 28, 2019
RHCS6: Install a two-node basic cluster
Viewed 4019 times since Sun, Jun 3, 2018
7 Tips – Tuning Command Line History in Bash
Viewed 6406 times since Fri, Jul 5, 2019
Need to set up yum repository for locally-mounted DVD on Red Hat Enterprise Linux 7
Viewed 3877 times since Mon, Oct 29, 2018
30 Handy Bash Shell Aliases For Linux / Unix / MacOS
Viewed 5745 times since Thu, Feb 11, 2021
Red Hat Cluster Tutorial
Viewed 2603 times since Sun, Jun 3, 2018
RHEL: Create a local RPM repository
Viewed 11993 times since Sun, May 27, 2018
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 3878 times since Tue, Aug 6, 2019
RHEL7: Create and configure LUKS-encrypted partitions and logical volumes to prompt for password and mount a decrypted file system at boot.
Viewed 14087 times since Mon, Aug 6, 2018