{"id":6228,"date":"2023-02-19T14:36:04","date_gmt":"2023-02-19T09:06:04","guid":{"rendered":"https:\/\/trysiteprice.com\/blog\/?p=6228"},"modified":"2023-02-19T14:36:04","modified_gmt":"2023-02-19T09:06:04","slug":"applescript-run-or-call-a-shell-script","status":"publish","type":"post","link":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/","title":{"rendered":"Applescript: Run or Call a Shell Script"},"content":{"rendered":"<p>To run or call a shell script from AppleScript, you can use the <code>do shell script<\/code> command. Here&#8217;s an example:<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-vbnet\"><span class=\"hljs-keyword\">set<\/span> myScriptPath <span class=\"hljs-keyword\">to<\/span> <span class=\"hljs-string\">\"\/path\/to\/my\/script.sh\"<\/span><br \/>\n<span class=\"hljs-keyword\">do<\/span> shell script myScriptPath<br \/>\n<\/code><\/div>\n<\/div>\n<p>In this example, the <code>myScriptPath<\/code> variable contains the path to the shell script that you want to run. The <code>do shell script<\/code> command then executes the script.<\/p>\n<p>If your shell script takes arguments, you can include them as a string after the script path, like this:<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-vbnet\"><span class=\"hljs-keyword\">set<\/span> myScriptPath <span class=\"hljs-keyword\">to<\/span> <span class=\"hljs-string\">\"\/path\/to\/my\/script.sh\"<\/span><br \/>\n<span class=\"hljs-keyword\">set<\/span> myScriptArgs <span class=\"hljs-keyword\">to<\/span> <span class=\"hljs-string\">\"arg1 arg2 arg3\"<\/span><br \/>\n<span class=\"hljs-keyword\">do<\/span> shell script myScriptPath &amp; <span class=\"hljs-string\">\" \"<\/span> &amp; myScriptArgs<br \/>\n<\/code><\/div>\n<\/div>\n<p>In this example, the <code>myScriptArgs<\/code> variable contains the arguments that you want to pass to the shell script, separated by spaces. The <code>&amp;<\/code> operator is used to concatenate the script path and arguments into a single string, which is then passed to the <code>do shell script<\/code> command.<\/p>\n<p>By default, the <code>do shell script<\/code> command runs the shell script using the <code>\/bin\/sh<\/code> shell. If you need to use a different shell, you can specify it as an optional parameter to the <code>do shell script<\/code> command, like this:<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-vbnet\"><span class=\"hljs-keyword\">set<\/span> myScriptPath <span class=\"hljs-keyword\">to<\/span> <span class=\"hljs-string\">\"\/path\/to\/my\/script.sh\"<\/span><br \/>\n<span class=\"hljs-keyword\">set<\/span> myShell <span class=\"hljs-keyword\">to<\/span> <span class=\"hljs-string\">\"\/bin\/bash\"<\/span><br \/>\n<span class=\"hljs-keyword\">do<\/span> shell script myScriptPath <span class=\"hljs-keyword\">with<\/span> administrator privileges user name <span class=\"hljs-string\">\"username\"<\/span> password <span class=\"hljs-string\">\"password\"<\/span> <span class=\"hljs-keyword\">with<\/span> administrator privileges <span class=\"hljs-built_in\">and<\/span> <span class=\"hljs-keyword\">with<\/span> shell myShell<br \/>\n<\/code><\/div>\n<\/div>\n<p>In this example, the <code>myShell<\/code> variable contains the path to the shell that you want to use. The <code>with shell<\/code> parameter is used to specify the shell to use with the <code>do shell script<\/code> command.<\/p>\n<p>The <code>with administrator privileges user name \"username\" password \"password\" with administrator privileges<\/code> parameters are used to run the shell script with elevated privileges (i.e. as an administrator). Note that you will need to replace &#8220;username&#8221; and &#8220;password&#8221; with a valid username and password for the system.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To run or call a shell script from AppleScript, you can use the do shell script command. Here&#8217;s an example: set myScriptPath to &#8220;\/path\/to\/my\/script.sh&#8221; do shell script myScriptPath In this example, the myScriptPath variable contains the path to the shell script that you want to run. The do shell script command then executes the script. &#8230; <a title=\"Applescript: Run or Call a Shell Script\" class=\"read-more\" href=\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\" aria-label=\"Read more about Applescript: Run or Call a Shell Script\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6228","post","type-post","status-publish","format-standard","hentry","category-best-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Applescript: Run or Call a Shell Script - TrySitePrice<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Applescript: Run or Call a Shell Script - TrySitePrice\" \/>\n<meta property=\"og:description\" content=\"To run or call a shell script from AppleScript, you can use the do shell script command. Here&#8217;s an example: set myScriptPath to &quot;\/path\/to\/my\/script.sh&quot; do shell script myScriptPath In this example, the myScriptPath variable contains the path to the shell script that you want to run. The do shell script command then executes the script. ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\" \/>\n<meta property=\"og:site_name\" content=\"TrySitePrice\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-19T09:06:04+00:00\" \/>\n<meta name=\"author\" content=\"Rahul Sahu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\"},\"author\":{\"name\":\"Rahul Sahu\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/#\/schema\/person\/358e04eeea4281deacad2f30c58e67f4\"},\"headline\":\"Applescript: Run or Call a Shell Script\",\"datePublished\":\"2023-02-19T09:06:04+00:00\",\"dateModified\":\"2023-02-19T09:06:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\"},\"wordCount\":205,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/trysiteprice.com\/blog\/#organization\"},\"articleSection\":[\"Best\/Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\",\"url\":\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\",\"name\":\"Applescript: Run or Call a Shell Script - TrySitePrice\",\"isPartOf\":{\"@id\":\"https:\/\/trysiteprice.com\/blog\/#website\"},\"datePublished\":\"2023-02-19T09:06:04+00:00\",\"dateModified\":\"2023-02-19T09:06:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trysiteprice.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Applescript: Run or Call a Shell Script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/#website\",\"url\":\"https:\/\/trysiteprice.com\/blog\/\",\"name\":\"TrySitePrice\",\"description\":\"Free Website Value Calculator Tool\",\"publisher\":{\"@id\":\"https:\/\/trysiteprice.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trysiteprice.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/#organization\",\"name\":\"TrySitePrice\",\"url\":\"https:\/\/trysiteprice.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/trysiteprice.com\/blog\/wp-content\/uploads\/2021\/12\/cropped-trysiteprice-logo.png\",\"contentUrl\":\"https:\/\/trysiteprice.com\/blog\/wp-content\/uploads\/2021\/12\/cropped-trysiteprice-logo.png\",\"width\":395,\"height\":268,\"caption\":\"TrySitePrice\"},\"image\":{\"@id\":\"https:\/\/trysiteprice.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/#\/schema\/person\/358e04eeea4281deacad2f30c58e67f4\",\"name\":\"Rahul Sahu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trysiteprice.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/51f0f95f7b95665f62baed2211572165?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/51f0f95f7b95665f62baed2211572165?s=96&d=mm&r=g\",\"caption\":\"Rahul Sahu\"},\"sameAs\":[\"https:\/\/trysiteprice.com\/blog\"],\"url\":\"https:\/\/trysiteprice.com\/blog\/author\/rsahu4242_trysiteprice\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Applescript: Run or Call a Shell Script - TrySitePrice","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/","og_locale":"en_US","og_type":"article","og_title":"Applescript: Run or Call a Shell Script - TrySitePrice","og_description":"To run or call a shell script from AppleScript, you can use the do shell script command. Here&#8217;s an example: set myScriptPath to \"\/path\/to\/my\/script.sh\" do shell script myScriptPath In this example, the myScriptPath variable contains the path to the shell script that you want to run. The do shell script command then executes the script. ... Read more","og_url":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/","og_site_name":"TrySitePrice","article_published_time":"2023-02-19T09:06:04+00:00","author":"Rahul Sahu","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#article","isPartOf":{"@id":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/"},"author":{"name":"Rahul Sahu","@id":"https:\/\/trysiteprice.com\/blog\/#\/schema\/person\/358e04eeea4281deacad2f30c58e67f4"},"headline":"Applescript: Run or Call a Shell Script","datePublished":"2023-02-19T09:06:04+00:00","dateModified":"2023-02-19T09:06:04+00:00","mainEntityOfPage":{"@id":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/"},"wordCount":205,"commentCount":0,"publisher":{"@id":"https:\/\/trysiteprice.com\/blog\/#organization"},"articleSection":["Best\/Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/","url":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/","name":"Applescript: Run or Call a Shell Script - TrySitePrice","isPartOf":{"@id":"https:\/\/trysiteprice.com\/blog\/#website"},"datePublished":"2023-02-19T09:06:04+00:00","dateModified":"2023-02-19T09:06:04+00:00","breadcrumb":{"@id":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/trysiteprice.com\/blog\/applescript-run-or-call-a-shell-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trysiteprice.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Applescript: Run or Call a Shell Script"}]},{"@type":"WebSite","@id":"https:\/\/trysiteprice.com\/blog\/#website","url":"https:\/\/trysiteprice.com\/blog\/","name":"TrySitePrice","description":"Free Website Value Calculator Tool","publisher":{"@id":"https:\/\/trysiteprice.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trysiteprice.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/trysiteprice.com\/blog\/#organization","name":"TrySitePrice","url":"https:\/\/trysiteprice.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trysiteprice.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/trysiteprice.com\/blog\/wp-content\/uploads\/2021\/12\/cropped-trysiteprice-logo.png","contentUrl":"https:\/\/trysiteprice.com\/blog\/wp-content\/uploads\/2021\/12\/cropped-trysiteprice-logo.png","width":395,"height":268,"caption":"TrySitePrice"},"image":{"@id":"https:\/\/trysiteprice.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/trysiteprice.com\/blog\/#\/schema\/person\/358e04eeea4281deacad2f30c58e67f4","name":"Rahul Sahu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trysiteprice.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/51f0f95f7b95665f62baed2211572165?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/51f0f95f7b95665f62baed2211572165?s=96&d=mm&r=g","caption":"Rahul Sahu"},"sameAs":["https:\/\/trysiteprice.com\/blog"],"url":"https:\/\/trysiteprice.com\/blog\/author\/rsahu4242_trysiteprice\/"}]}},"_links":{"self":[{"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/posts\/6228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/comments?post=6228"}],"version-history":[{"count":1,"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/posts\/6228\/revisions"}],"predecessor-version":[{"id":6229,"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/posts\/6228\/revisions\/6229"}],"wp:attachment":[{"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/media?parent=6228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/categories?post=6228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trysiteprice.com\/blog\/wp-json\/wp\/v2\/tags?post=6228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}