{"id":54974,"date":"2022-02-23T03:01:58","date_gmt":"2022-02-22T17:01:58","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=54974"},"modified":"2022-02-23T12:11:26","modified_gmt":"2022-02-23T02:11:26","slug":"php-calls-macos-apple-script-integration-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-calls-macos-apple-script-integration-tutorial\/","title":{"rendered":"PHP Calls macOS Apple Script Integration 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 Integration Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url_parent.jpg\" title=\"PHP Calls macOS Apple Script Integration Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP Calls macOS Apple Script Integration Tutorial<\/p><\/div>\n<p>Building on yesterday&#8217;s <a title='PHP Calls macOS Apple Script Primer Tutorial' href='#phpcosaspt'>PHP Calls macOS Apple Script Primer Tutorial<\/a> we want to integrate yesterday&#8217;s start onto the recent &#8230;<\/p>\n<ul>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/what_is_the_english_word.php------GETME\" title=\"what_is_the_english_word.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/what_is_the_english_word.php------GETME\" title=\"what_is_the_english_word.php\">what_is_the_english_word.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/what_is_the_english_word.php\" title=\"Click picture\">English Word Guessing Game<\/a> up at the RJM Programming public domain<\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/start_word_for_wordle_helper.php-----GETME\" title=\"start_word_for_wordle_helper.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/start_word_for_wordle_helper.php-----GETME\" title=\"start_word_for_wordle_helper.php\">start_word_for_wordle_helper.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/start_word_for_wordle_helper.php\" title=\"Click picture\">Start Word for Wordle Suggestions<\/a> up at the RJM Programming public domain<\/li>\n<\/ul>\n<p> &#8230; as macOS (perhaps <a target=_blank title='MAMP' href='http:\/\/www.mamp.info'>MAMP<\/a> local Apache\/PHP\/MySql web server) &#8220;Intranet style&#8221; integrations using the two lynchpins &#8230;<\/p>\n<ul>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.js_GETME\" title=\"apple_script_url.js\">apple_script_url.js<\/a> external Javascript called (in the integrated PHP above) via &#8230;<br \/>\n&lt;?php echo &#8221;<br \/>\n<code><br \/>\n&lt;script type='text\/javascript' src='apple_script_url.js'&gt;&lt;\/script&gt;<br \/>\n<\/code><br \/>\n&#8220;; ?&gt;<br \/>\n &#8230; just (needed) up at the RJM Programming public domain (perhaps in the same folder as the integrated PHP)<\/li>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.php-GETME\" title=\"apple_script_url.php\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.php-GETME\" title=\"apple_script_url.php\">apple_script_url.php<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/apple_script_url.php?url=https:\/\/google.com\" title=\"Click picture\">link to a pressing of an Apple Script window Play button to open Google search engine<\/a> up at the RJM Programming public domain and 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<\/li>\n<\/ul>\n<p> &#8230; leading to a top right &#128221; emoji button accessing these <a target=_blank title='AppleScript information from Apple' href='https:\/\/developer.apple.com\/library\/archive\/documentation\/AppleScript\/Conceptual\/AppleScriptLangGuide\/introduction\/ASLR_intro.html'>Apple Scripts<\/a> saved over at the macOS system&#8217;s &#8220;home Desktop&#8221; folder, ready for ongoing recall and extending.  Is this an <i>intersessional<\/i> (macOS or Mac OS X only) feeling piece of functionality that interests you?  Well, get downloading (and perhaps) tweaking, to find out!<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/php-calls-macos-apple-script-integration-tutorial\/'>PHP Calls macOS Apple Script Integration Tutorial<\/a>.<\/p-->\n<hr>\n<p id='phpcosaspt'>Previous relevant <a target=_blank title='PHP Calls macOS Apple Script Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php-calls-macos-apple-script-primer-tutorial\/'>PHP Calls macOS Apple Script Primer Tutorial<\/a> is shown below.<\/p>\n<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<hr>\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='#d54974' onclick='var dv=document.getElementById(\"d54974\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/external-javascript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d54974' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Building on yesterday&#8217;s PHP Calls macOS Apple Script Primer Tutorial we want to integrate yesterday&#8217;s start onto the recent &#8230; the changed what_is_the_english_word.php&#8216;s English Word Guessing Game up at the RJM Programming public domain the changed start_word_for_wordle_helper.php&#8216;s Start Word for &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-calls-macos-apple-script-integration-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/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,385,3606,405,3910,409,614,624,652,714,2178,744,3049,2427,932,997,1168,3911,1319,1402],"class_list":["post-54974","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-emoji","tag-emoji-button","tag-exec","tag-execute","tag-external-javascript","tag-integration","tag-intranet","tag-javascript","tag-local-web-server","tag-macos","tag-mamp","tag-open","tag-passthru","tag-php","tag-programming","tag-software-integration","tag-terminla","tag-tutorial","tag-web-application"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/54974"}],"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=54974"}],"version-history":[{"count":4,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/54974\/revisions"}],"predecessor-version":[{"id":54978,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/54974\/revisions\/54978"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=54974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=54974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=54974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}