{"id":54964,"date":"2022-02-22T03:01:34","date_gmt":"2022-02-21T17:01:34","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=54964"},"modified":"2022-02-22T09:56:37","modified_gmt":"2022-02-21T23:56:37","slug":"php-calls-macos-apple-script-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-calls-macos-apple-script-primer-tutorial\/","title":{"rendered":"PHP Calls macOS Apple Script Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.php?url=https:\/\/google.com\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Calls macOS Apple Script Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.jpg\" title=\"PHP Calls macOS Apple Script Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP Calls macOS Apple Script Primer Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/apple-script-execution-of-start-word-suggestions-for-wordle-tutorial\/' title='Apple Script Execution of Start Word Suggestions for Wordle Tutorial'>Apple Script Execution of Start Word Suggestions for Wordle Tutorial<\/a> struck a chord of interest for us.  Its use of &#8230;<\/p>\n<ul>\n<li>macOS command line via Terminal application &#8230;<\/li>\n<li><a target=_blank title='AppleScript information from Apple' href='https:\/\/developer.apple.com\/library\/archive\/documentation\/AppleScript\/Conceptual\/AppleScriptLangGuide\/introduction\/ASLR_intro.html'>Apple Script<\/a>ing &#8230; and &#8230;<\/li>\n<li>&#8220;open&#8221; command on that command line<\/li.\n<\/ul>\n<p> &#8230; opens the door to an idea we&#8217;ve wondered about before &#8230; perhaps involve multiple web browser &#8220;brands&#8221; in a single &#8230;<\/p>\n<ul>\n<li>web application<\/li>\n<li>command line application<\/li>\n<li>curl web application<\/li>\n<\/ul>\n<p> &#8230; using <font size=1>&#8230; you guessed it &#8230;<\/font> PHP in (what we see as) its 3 modes of use.<\/p>\n<p>Here&#8217;s our first draft of <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.php_GETME\">apple_script_url.php<\/a> we want you to download to (the Document Root of) a macOS <a target=_blank title='MAMP' href='http:\/\/www.mamp.info'>MAMP<\/a> local Apache\/PHP\/MySql web server environment, ideally, though you can tailor for another macOS local web server arrangement, perhaps &#8230;<\/p>\n<p><code><br \/>\n&lt;?php<br \/>\n\/\/ apple_script_url.php<br \/>\n\/\/ RJM Programming<br \/>\n\/\/ February 2022<br \/>\n<br \/>\n$ts=date('_dmY_his', time());<br \/>\n<br \/>\nif (isset($argc)) {<br \/>\n  if (PHP_OS == \"Darwin\") {<br \/>\n    if ($argc &gt;= 2) {<br \/>\n     if (file_exists(getenv('HOME') . '\/Desktop\/MyAppleScript' . $ts . '.scpt')) {<br \/>\n       unlink(getenv('HOME') . '\/Desktop\/MyAppleScript' . $ts . '.scpt');<br \/>\n     }<br \/>\n     file_put_contents(getenv('HOME') . '\/Desktop\/MyAppleScript' . $ts . '.scpt', \"tell application \\\"Terminal\\\"\\n\tactivate\\n\tdo script \\\"cd '\" . getenv('HOME') . '\/Desktop' . \"'\\\" in window 1\\n\tdo script \\\"open '\" . $argv[1] . \"'\\\" in window 1\\nend tell\");<br \/>\n     exec(\"cd \" . getenv('HOME') . '\/Desktop ; open MyAppleScript' . $ts . '.scpt');<br \/>\n    }<br \/>\n  }<br \/>\n} else if (isset($_GET['url'])) {<br \/>\n  if (PHP_OS == \"Darwin\") {<br \/>\n    if (file_exists(getenv('HOME') . '\/Desktop\/MyAppleScript' . $ts . '.scpt')) {<br \/>\n       unlink(getenv('HOME') . '\/Desktop\/MyAppleScript' . $ts . '.scpt');<br \/>\n    }<br \/>\n    file_put_contents(getenv('HOME') . '\/Desktop\/MyAppleScript' . $ts . '.scpt', \"tell application \\\"Terminal\\\"\\n\tactivate\\n\tdo script \\\"cd '\" . getenv('HOME') . '\/Desktop' . \"'\\\" in window 1\\n\tdo script \\\"open '\" . str_replace('+','%20',$_GET['url']) . \"'\\\" in window 1\\nend tell\");<br \/>\n    \/\/exec('open \\\"' . getenv('HOME') . '\/Desktop\/MyAppleScript' . $ts . '.scpt\\\"');<br \/>\n    passthru(\"cd \" . getenv('HOME') . '\/Desktop ; open MyAppleScript' . $ts . '.scpt');<br \/>\n  } else if (strpos($_SERVER['SERVER_NAME'], 'localhost') === false) {<br \/>\n    echo \"&lt;html&gt;&lt;body onload=\\\" window.open('HTTP:\/\/localhost:8888\/apple_script_url.php?url=\" . str_replace('+','%20',$_GET['url']) . \"','_self');  \\\"&gt;&lt;\/body&gt;&lt;\/html&gt;\";<br \/>\n  }<br \/>\n}<br \/>\n?&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; and if you have downloaded, you may get some joy with it calling <a target=_blank title=Google href='https:\/\/google.com'>Google<\/a> into a new web browser arrangement <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.php?url=https:\/\/google.com\" title=\"Click picture\">via the pressing of an Apple Script window Play button<\/a> &#8230; or &#8230; get to the macOS Terminal prompt and type &#8230;<\/p>\n<p><code><br \/>\nphp \/Applications\/MAMP\/htdocs\/apple_script_url.php https:\/\/google.com<br \/>\n<\/code><\/p>\n<p> &#8230; or &#8230;<\/p>\n<p><code><br \/>\ncurl \"HTTP:\/\/localhost:8888\/apple_script_url.php?url=https:\/\/google.com\"<br \/>\n<\/code><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d54964' onclick='var dv=document.getElementById(\"d54964\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/command-line\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d54964' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s Apple Script Execution of Start Word Suggestions for Wordle Tutorial struck a chord of interest for us. Its use of &#8230; macOS command line via Terminal application &#8230; Apple Scripting &#8230; and &#8230; &#8220;open&#8221; command on that command line<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[85,3909,233,234,284,319,360,405,3910,714,2178,744,3049,2427,932,997,3911,1319,1402],"class_list":["post-54964","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-apache","tag-apple-script","tag-command","tag-command-line","tag-curl","tag-desktop","tag-download","tag-exec","tag-execute","tag-local-web-server","tag-macos","tag-mamp","tag-open","tag-passthru","tag-php","tag-programming","tag-terminla","tag-tutorial","tag-web-application"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/54964"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=54964"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/54964\/revisions"}],"predecessor-version":[{"id":54973,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/54964\/revisions\/54973"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=54964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=54964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=54964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}