PHP Calls Windows and macOS Nimh Game Integration Tutorial

PHP Calls Windows and macOS Nimh Game Integration Tutorial

PHP Calls Windows and macOS Nimh Game Integration Tutorial

On top of yesterday’s PHP Calls Windows and macOS Gimp Guillotine Follow Up Tutorial‘s progress with our “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool integrations, today …

  • improving a filename length issue integrating with our Nimh game … and also …
  • add some sharing “double click” logic for …
    1. email via the default email client application, where body content is the same URL link we are interested in with Apple Script or DOS Batch interfacing … or …
    2. SMS via the default SMS client application, if clicking the bottom right part of the “emoji button” in an “a” element, as per …

      function postplayme() {
      var aois=document.getElementById('asue');
      aois.title='Now email off this URL link. ' + '' + aois.title;
      aois.href='mailto:?subject=Email%20URL%20Snapshot%20%2e%2e%2e&body=' + encodeURIComponent(document.URL.split('#')[0]);
      aois.target='_top';
      }

      function justplayme(aoisev) {
      var aax=0, aay=0, aarect=null, vsx=0, vsy=0, recipt='';
      if (locfound) {
      var aois=aoisev.target;
      if (('' + document.URL).indexOf(mustcontainc) != -1 && aois.title.indexOf(' ... ') == -1) {
      if (('' + aois.href).replace(/^null/g,'') == '') {
      if (aoisev.clientX) {
      aax = aoisev.clientX;
      aay = aoisev.clientY;
      } else {
      aax = aoisev.pageX;
      aay = aoisev.pageY;
      }
      aarect=aois.getBoundingClientRect();
      vsx=eval(eval('' + aarect.left) + eval(eval('' + aarect.width) * 0.70));
      vsy=eval(eval('' + aarect.top) + eval(eval('' + aarect.height) * 0.70));
      //if (eval('' + aax) >= vsx) { alert('X is SMS aay=' + aay + ' should be greater than vsy=' + vsy + ' aarect.bottom=' + aarect.bottom + ' aarect.top=' + aarect.top + ' aarect.height=' + aarect.height); }
      //if (eval('' + aay) >= vsy) { alert('Y is SMS'); }
      if (eval('' + aax) >= vsx && eval('' + aay) >= vsy) {

      recipt=prompt('Enter SMS or email address to send to.', '');
      if (recipt == null) { recipt=''; }
      if (recipt.trim() != '') {
      if (recipt.trim().indexOf('@') > 0) {
      aois.title='Now email off this URL link ... ' + '' + aois.title;
      aois.href='mailto:' + recipt.trim() + '?subject=Email%20URL%20Snapshot%20%2e%2e%2e&body=' + encodeURIComponent(document.URL.split('#')[0]);
      aois.target='_top';
      aois.click();
      } else if (recipt.trim().replace(/0/g,'').replace(/1/g,'').replace(/2/g,'').replace(/3/g,'').replace(/4/g,'').replace(/5/g,'').replace(/6/g,'').replace(/7/g,'').replace(/8/g,'').replace(/9/g,'') == '') {
      aois.title='Now SMS off this URL link ... ' + '' + aois.title;
      aois.href='sms:' + recipt.trim() + '&body=' + encodeURIComponent(document.URL.split('#')[0]);
      aois.target='_top';
      aois.click();
      }
      }
      } else {
      setTimeout(postplayme, 2000);
      //aois.title='Now email off this URL link. ' + '' + aois.title;
      //aois.href='mailto:?subject=Email%20URL%20Snapshot%20%2e%2e%2e&body=' + encodeURIComponent(document.URL.split('#')[0]);
      //aois.target='_top';
      }
      //if (document.URL.indexOf('why=') != -1) {
      // asuwo=window.open(firstloc + 'apple_script_url.php?justplay=y&showothers=y&tsplus=' + encodeURIComponent(document.URL.split('#')[0].split('&blurb=Sorry')[0].replace('HTTP','http').replace(/\./g,'_').replace(/\?/g,'_').replace(/\&/g,'_').replace(/\=/g,'_').replace(/\:/g,'_').replace(/\//g,'_').replace(/\,/g,'_').replace(/\[/g,'_').replace(/\]/g,'_').replace(/\~/g,'_').replace(/\`/g,'_')).replace(/\%20/g,'_').replace(/\+/g,'_') + '&url=' + encodeURIComponent(document.URL.split('#')[0].split('&blurb=Sorry')[0]),'_blank','top=50,left=50,width=500,height=500');
      // setTimeout(checkasu, 35000);
      //} else {
      if (nothingis != '') {
      documentURL=document.URL;
      while (documentURL.indexOf(nothingis) != -1) {
      documentURL=documentURL.replace(nothingis,'');
      }
      asuwo=window.open(firstloc + 'apple_script_url.php?justplay=y¬hing=' + encodeURIComponent(nothingis) + '&showothers=y&tsplus=' + encodeURIComponent(documentURL.split('#')[0].split('&blurb=Sorry')[0].replace('HTTP','http').replace(/\./g,'_').replace(/\?/g,'_').replace(/\&/g,'_').replace(/\=/g,'_').replace(/\:/g,'_').replace(/\//g,'_').replace(/\,/g,'_').replace(/\[/g,'_').replace(/\]/g,'_').replace(/\~/g,'_').replace(/\`/g,'_').replace(/\%\)/g,'__').replace(/\(/g,'_').replace(/\)/g,'_').replace(/\//g,'_').replace(/\{/g,'_').replace(/\}/g,'_').replace(/\:/g,'_').replace(/\*/g,'_').replace(/\$/g,'_').replace(/\,/g,'_').replace(/\./g,'_').replace(/\;/g,'_')).replace(/\%20/g,'_').replace(/\+/g,'_') + '&url=' + encodeURIComponent(document.URL.split('#')[0].split('&blurb=Sorry')[0]),'_blank','top=50,left=50,width=50,height=50');
      } else {
      asuwo=window.open(firstloc + 'apple_script_url.php?justplay=y&showothers=y&tsplus=' + encodeURIComponent(document.URL.split('#')[0].split('&blurb=Sorry')[0].replace('HTTP','http').replace(/\./g,'_').replace(/\?/g,'_').replace(/\&/g,'_').replace(/\=/g,'_').replace(/\:/g,'_').replace(/\//g,'_').replace(/\,/g,'_').replace(/\[/g,'_').replace(/\]/g,'_').replace(/\~/g,'_').replace(/\`/g,'_').replace(/\%\)/g,'__').replace(/\(/g,'_').replace(/\)/g,'_').replace(/\//g,'_').replace(/\{/g,'_').replace(/\}/g,'_').replace(/\:/g,'_').replace(/\*/g,'_').replace(/\$/g,'_').replace(/\,/g,'_').replace(/\./g,'_').replace(/\;/g,'_')).replace(/\%20/g,'_').replace(/\+/g,'_') + '&url=' + encodeURIComponent(document.URL.split('#')[0].split('&blurb=Sorry')[0]),'_blank','top=50,left=50,width=50,height=50');
      }
      setTimeout(checkasu, 5000);
      //}
      }
      }
      }
      }

Our PHP code got tweaked, and the macOS (Terminal application) command line problem below …

zsh: file name too long

… tweaked upon via temporary and strategic “file_put_contents” PHP codelines …

<?php

if (isset($_GET['tsplus'])) {
// .replace(/\%\)/g,'__').replace(/\(/g,'_').replace(/\)/g,'_').replace(/\//g,'_').replace(/\{/g,'_').replace(/\}/g,'_').replace(/\:/g,'_').replace(/\*/g,'_').replace(/\$/g,'_').replace(/\,/g,'_').replace(/\./g,'_').replace(/\;/g,'_')
if (isset($_GET['nothing'])) {
$tsplus= str_replace('.','_', str_replace(',','_', str_replace('*','_', str_replace('$','_', str_replace(':','_', str_replace(';','_', str_replace('}','_', str_replace('{','_', str_replace('/','_', str_replace(')','_', str_replace('(','_', str_replace('%)','__', str_replace(str_replace('+',' ',urldecode($_GET['nothing'])), '', str_replace(' ','',str_replace('+','',urldecode($_GET['tsplus']))) ) ))))))))))));
//file_put_contents('xxxx0xx.vvvvvv', str_replace(' ','',str_replace('+','',urldecode($_GET['tsplus']))) . ' ... ' . $tsplus);
} else {
$tsplus= str_replace('.','_', str_replace(',','_', str_replace('*','_', str_replace('$','_', str_replace(':','_', str_replace(';','_', str_replace('}','_', str_replace('{','_', str_replace('/','_', str_replace(')','_', str_replace('(','_', str_replace('%)','__', str_replace(' ','',str_replace('+','',urldecode($_GET['tsplus']))) ))))))))))));
//file_put_contents('xxxx1xx.vvvvvv', $tsplus);
}
//file_put_contents('xxxxxx.vvvvvv', $tsplus);
}

?>

… to arrive at a new strategy (and new argument (a less than 5 minute one)) used in the new Nimh Game codeline …

<?php

<script type='text/javascript' src='/apple_script_url.js?mustconZtain=&&lefXt=calc(50% - 85px)&toXp=calc(50% + 80px)&emojXi=128220&csXs=font-size:30px;opacity:0.8;¬hing=,'></script>

?>

… that won the day getting the filename lengths back in order with …

  1. the changed apple_script_url.php‘s link to a pressing of an Apple Script window Play button to open Google search engine, the PHP code for which we want you to download to (the Document Root of) a macOS or Windows MAMP local Apache/PHP/MySql web server environment, ideally, though you can tailor for another macOS local web server arrangement)
  2. the changed “external Javascript” apple_script_url.js (which is only needed up at the RJM Programming domain (when using RJM Programming domain web applications that is))


Previous relevant PHP Calls Windows and macOS Gimp Guillotine Follow Up Tutorial is shown below.

PHP Calls Windows and macOS Gimp Guillotine Follow Up Tutorial

PHP Calls Windows and macOS Gimp Guillotine Follow Up Tutorial

It’s amazing with integration how data springs up surprises. Just as you think your tool is bulletproof, data issues can come and spoil the Barty party. On the same theme as yesterday’s PHP Calls Windows and macOS Google Charts and Blog Tutorial we wanted to integrate the recent “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool with the “Gimp Guillotine Follow Up” web application featuring lots of ways to represent a set of related images.

Another overcomable issue arose thinking about this. We think it is wise quite often when using navigation via …

  • PHP (or other serverside code) … using …
  • HTML element form … with …
  • action=[the same URL as the form belongs to] … or … (the “here’s looking at you, kid”, clause”)

… to also use method=POST because the data sizes (involved with the form navigation) might make “method=GET” alternative approach unviable (and you get HTTP error 414). But here’s an occasion, integrating this recent “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool, where “method=GET” comes back into our thinking. Why? Well, with “method=GET” being used with the HTML form, we can end up with some useful and meaningful macOS or Windows Desktop folder files describing a situation that you might want to retain and recover (the same scenario of) at a later date. And now that we are happy we can discover whether the “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool exists or not, we can switch from …

  • form method=POST to …
  • method=GET … if we amend the document.body onload event function “selopts” as per
    <?php echo ”

    function selopts() {
    if (document.getElementById('asue') && eval('' + document.getElementsByTagName('form').length) > 0) {
    document.getElementsByTagName('form')[0].method='GET';
    }

    " . $selopts . "
    }

    “; ?>
    … dynamically (and only as potentially needed), and teamed with the new “within head element” …
    <?php echo ”

    <script type='text/javascript' src='apple_script_url.js?mustconXtain=&&lefXt=calc(50% - 85px)&toXp=calc(50% + 80px)&emojXi=128220&csXs=font-size:30px;opacity:0.8;></script>

    “; ?>
    … in the changed gimp_guillotine_followup.php that you can try out at this live run link

… all “good to go” where the data length won’t exceed method=GET URL length limits around 800-900 characters we seem to have up at the RJM Programming domain webpages. Happily, in the case of “Gimp Guillotine Follow Up” work, this should not be a problem. Sadly, in many other method=POST PHP scenarios, this will not be the case.

And then, as far as data complexity goes, yes, this “Gimp Guillotine Follow Up” integrating got us “a bit kludgy” amending …

  1. the changed apple_script_url.php‘s link to a pressing of an Apple Script window Play button to open Google search engine, the PHP code for which we want you to download to (the Document Root of) a macOS or Windows MAMP local Apache/PHP/MySql web server environment, ideally, though you can tailor for another macOS local web server arrangement)
    <?php

    if (isset($_GET['tsplus'])) {
    $tsplus= str_replace('.','_', str_replace(',','_', str_replace('*','_', str_replace('$','_', str_replace(':','_', str_replace(';','_', str_replace('}','_', str_replace('{','_', str_replace('/','_', str_replace(')','_', str_replace('(','_', str_replace('%)','__', str_replace(' ','',str_replace('+','',urldecode($_GET['tsplus']))) ))))))))))));
    }

    ?>
    … the symptom of there being a problem is that no Desktop files are created if these data massages allow through characters not suited to file naming (on a hard disk) purposes
  2. a changed “external Javascript” apple_script_url.js (which is only needed up at the RJM Programming domain (when using RJM Programming domain web applications that is))


Previous relevant PHP Calls Windows and macOS Google Charts and Blog Tutorial is shown below.

PHP Calls Windows and macOS Google Charts and Blog Tutorial

PHP Calls Windows and macOS Google Charts and Blog Tutorial

We tackle two more integrations of our current “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool (made up of external Javascript and local web server downloaded PHP), those being …

  • the blog you are reading … a one line change into our TwentyTen themed header.php’s …
    <?php echo ”

    <script type='text/javascript' src='/apple_script_url.js?mustconXtain=&&left=calc(65% + 11px)&top=calc(0% + 58px)&emojXi=128220&css=font-size:22px;opacity:0.8;'></script>

    “; ?>
    … for non-mobile users that is
  • our inhouse Google Chart interfacers such as Pie Chart … for non-mobile users that is

… onto yesterday’s PHP Calls Windows Batch Genericization Tutorial “end of our genericizations drive(for the forseeable future).

Hang on! There are quite a few Google Chart interfacers (eg. Line Chart, TimeLine Chart, Histogram Chart, Map Chart, Geo Chart etcetera etcetera etcetera), so that must have been a lot of work?! Well, no, it wasn’t, because we intervened into another external Javascript’s workings which is called by all these interfacers, and so only needed to …

  • change this way

    function ggmuchlater() {
    var scriptz = document.createElement("script"); // create a script DOM node
    scriptz.src = '/apple_script_url.js?left=calc(100% - 60px)&top=2px&emojXi=128220&css=font-size:30px;opacity:0.8;&mustcontain=&'; // set its src to the provided URL
    document.head.appendChild(scriptz); // add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead) ... thanks to https://dev-answers.com/solutions/3287e028/how-do-i-include-a-javascript-file-in-another-javascript-file
    }

    setTimeout(ggmuchlater, 7000);

    … the gchartgen.js Google Chart interfacing helper external Javascript (only needed up at the RJM Programming domain) … thanks to https://dev-answers.com/solutions/3287e028/how-do-i-include-a-javascript-file-in-another-javascript-file … but this change required, also …
  • a strategically changed “external Javascript” apple_script_url.js, featuring Ajax

    var gczhr=null;
    var plusscr='';
    var retgcval='';


    function gcshowStuff() {
    if (gczhr != null) {
    if (gczhr.readyState == 4) {
    if (gczhr.status == 200) {
    plusscr+=gczhr.responseText;
    }
    }
    }
    }


    function gcajaxit(gcurlis) {
    gczhr = new XMLHttpRequest();
    gczhr.open('get', gcurlis, true);
    gczhr.onreadystatechange = gcshowStuff;
    gczhr.send(null);
    }


    function changethedefaultsmaybe() {
    var defpallette='', thisonepal='', calcpal='', calcper='', icalcper=-1, proposedport='';
    if (document.head.innerHTML.indexOf('apple_s' + 'cript_url.js?') == -1 && document.head.innerHTML.indexOf('/gchart' + 'gen.js') != -1 && plusscr == '') {
    var efforts=document.head.innerHTML.split('/gchart' + 'gen.js');
    var slicerz=-1;
    var gcslicerz='';
    while (slicerz < 0) {
    if (efforts[0].slice(slicerz).substring(0,1) == "'" || efforts[0].slice(slicerz).substring(0,1) == '"' || efforts[0].slice(slicerz).substring(0,1) == '=') {
    slicerz=0;
    } else {
    gcslicerz=efforts[0].slice(slicerz).substring(0,1) + gcslicerz;
    slicerz--;
    }
    }
    gcajaxit(gcslicerz + '/gchart' + 'gen.js');
    return '1';
    }

    if ((document.head.innerHTML + plusscr).indexOf('apple_s' + 'cript_url.js?') != -1) {
    defpallette=(document.head.innerHTML + plusscr).split('apple_s' + 'cript_url.js?')[1].split('>')[0].split('"')[0].split("'")[0].replace(/\&\;/g,'&').replace(/mustcontain\=\&$/g, 'mustcontain=' + encodeURIComponent('&')).replace('mustcontain=&&', 'mustcontain=' + encodeURIComponent('&') + '&').replace('mustcontain=&#', 'mustcontain=' + encodeURIComponent('&') + '#');
    // rest in this if block unchanged
    }
    // rest unchanged in this function, except at the end of this function ...
    return '';
    }

    // ... then ... at the end of the external Javascript file ...

    function anotherajaxgo() {
    changethedefaultsmaybe();
    asuwo=window.open(firstloc + 'apple_script_url.php?imagetest=apple_script_url_test.jpg','_blank','top=' + deftop + ',left=' + defleft + ',width=50,height=50');
    setTimeout(checkasu, 2000);
    }


    if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
    retgcval=changethedefaultsmaybe();
    if (retgcval != '') {
    plusscr=' ';
    setTimeout(anotherajaxgo, 4000);
    } else {

    asuwo=window.open(firstloc + 'apple_script_url.php?imagetest=apple_script_url_test.jpg','_blank','top=' + deftop + ',left=' + defleft + ',width=50,height=50');
    setTimeout(checkasu, 2000);
    }
    }

    … calls, “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool external Javascript component (only needed up at the RJM Programming domain)

Note, how with the Google Charts interfacing, we made use of the “end of argument list” …


&mustcontain=&

… inclusion to limit the “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool enthusiasms to the situations after the user has entered in all their interactive inputs they perform in Javascript prompt windows.

Nothing changed, here, today regarding our “PHP Calls Windows (DOS Batch) and macOS (Apple Script) URL Recall” tool PHP apple_script_url.php‘s link to a pressing of an Apple Script window Play button to open Google search engine, the PHP code for which we want you to download to (the Document Root of) a macOS or Windows MAMP local Apache/PHP/MySql web server environment, ideally, though you can tailor for another macOS local web server arrangement).


Previous relevant PHP Calls Windows Batch Genericization Tutorial is shown below.

PHP Calls Windows Batch Genericization Tutorial

PHP Calls Windows Batch Genericization Tutorial

Just to buck our usual trend in a thread of related blog postings we leave alone the title’s second last word of yesterday’s PHP Calls macOS Apple Script Genericization Tutorial to create today’s title. The reason is …

  • yesterday’s genericization was on the client side (external Javascript) of the “PHP Calls” (command line opener of a web browser address bar URL in that operating system’s default web browser) allowing “parent master callers” of our external Javascript/PHP tool control aesthetics and positioning (and a rudimentary filter to usage) … whereas …
  • today’s genericization (turns hardcodings into arguments (but none from me … boom boom!)) affects the server side (PHP) adding Windows operating system client computer support via DOS Batch start URL commands (to add to the existent macOS Apple Script open URL commands)

Some of the genericization checklist (in the changed apple_script_url.php‘s link to a pressing of an Apple Script window Play button to open Google search engine, the PHP code for which we want you to download to (the Document Root of) a macOS or Windows MAMP local Apache/PHP/MySql web server environment, ideally, though you can tailor for another macOS local web server arrangement) items went …

  1. change any operating system folder delimiter / hardcodings should become DIRECTORY_SEPARATOR
  2. change if (PHP_OS == “Darwin”) { … } hardcodings should become if (PHP_OS == “Darwin” || PHP_OS == ‘WINNT’ || PHP_OS == ‘WIN32’ || PHP_OS == ‘Windows’) { … } for combined parts versus if (PHP_OS == ‘WINNT’ || PHP_OS == ‘WIN32’ || PHP_OS == ‘Windows’) { … } for Windows only versus if (PHP_OS == “Darwin”) { … } for macOS only
  3. a lot of the rest of genericizations work because of …
    <?php

    $localsug='HTTP://localhost:8888/';

    if (PHP_OS == 'WINNT' || PHP_OS == 'WIN32' || PHP_OS == 'Windows') {
    $homename='USERPROFILE';
    $localsug='HTTP://localhost/';
    $openverb='start';
    $openext='.bat';
    $tellprefix='';
    } else {
    $homename='HOME';
    $openverb='open';
    $openext='.scpt';
    $tellprefix="tell application \"Terminal\"\n activate\n do script \"cd '" . getenv($homename) . DIRECTORY_SEPARATOR . 'Desktop' . "'\" in window 1\n do script \"";
    }

    function wincomplexity($inurl) {
    if (PHP_OS == 'WINNT' || PHP_OS == 'WIN32' || PHP_OS == 'Windows') {
    $outurl=str_replace('&', '^&', $inurl);
    $huhs=explode("'", $outurl);
    if (sizeof($huhs) >= 3) { return ' ' . $huhs[1]; }
    return explode('"', $outurl)[0];
    }
    return $inurl;
    }

    ?>

… and as far as localhost port decisions go, we cater for two passes of possibilities (in a mildly changed “external Javascript” apple_script_url.js) …

  • first pass using localhost:8888 … suiting what we are familiar with in macOS MAMP local Apache/PHP/MySql web server … and as of today …
  • second pass using localhost (where the assumed :80 is not needed)suiting what we are familiar with in Windows MAMP local Apache/PHP/MySql web server usage …

    var portstr=':8888';
    var firstloc='HTTP://localhost' + portstr + '/';
    var locfound=false;
    var asuwo=null;

    function checkasu() {
    if (asuwo.closed) { // local web server there
    if (!locfound) {
    if (portstr == '') {
    document.body.innerHTML+='<style> #asue { position:fixed; left:' + defcssleft + '; top:' + defcsstop + '; z-index:99; cursor:pointer; ' + cssoverriders + ' } </style><div onclick=justplayme(); title="DOS Batch script snapshot re-execution via Windows Desktop" id=asue>&#' + emojin + ';</div>';
    } else {

    document.body.innerHTML+='<style> #asue { position:fixed; left:' + defcssleft + '; top:' + defcsstop + '; z-index:99; cursor:pointer; ' + cssoverriders + ' } </style><div onclick=justplayme(); title="Apple Script snapshot re-execution via macOS Desktop" id=asue>&#' + emojin + ';</div>';
    }
    }
    locfound=true;
    asuwo=null;
    } else {
    if (!locfound && firstloc != 'HTTP://localhost/') {
    portstr='';
    firstloc='HTTP://localhost' + portstr + '/';
    asuwo.close();
    asuwo=null;
    asuwo=window.open(firstloc + 'apple_script_url.php?imagetest=apple_script_url_test.jpg','_blank','top=' + deftop + ',left=' + defleft + ',width=50,height=50');
    setTimeout(checkasu, 2000);
    } else {

    asuwo.close();
    asuwo=null;
    }
    locfound=false;
    }
    }

Windows (via DOS … shhhhhhh … it’s a mute point) usage lessens the stress on your button pressing digits, not needing any Play button additional presses, as Apple Script does.


Previous relevant PHP Calls macOS Apple Script Genericization Tutorial is shown below.

PHP Calls macOS Apple Script Genericization Tutorial

PHP Calls macOS Apple Script Genericization Tutorial

We often set off an “integration” project, and make it work for “Case 1” (akin to Mathematical Induction where you prove for “Case 1”, then prove for “Case 2” and then prove for “Case n”) and wake up the next day facing what is hard for us, as a programmer, to bear … hardcodings that many a programmer will want to “Genericize” out in favour of “Arguments” (but none from me … tee hee!)

And so, today’s task on top of yesterday’s PHP Calls macOS Apple Script Integration Tutorial‘s (all important) “proof of integration concept” work, is to “Genericize” in terms of user control of the “emoji button” look and positioning and sizing (ie. its CSS styling).

Why bother? Now is the time to ask … true. It’s because we envisage this changed “external Javascript” apple_script_url.js can be useful as a servant (or child “tool”) to many and varied masters (or parent “callers”), and it will be useful to not have too many versions of the tool just displaying the “emoji button” differently, but rather, allow the master code be able to control this “emoji button” look, but calling on the same source code. Exemplifying this in today’s tutorial picture we added call arguments in …

<?php echo ”

<script type='text/javascript' src='apple_script_url.js?left=calc(50% - 85px)&top=calc(50% + 80px)&emoji=128220&css=font-size:30px;opacity:0.8;'></script>

“; ?>

… to achieve this


// apple_script_url.js
// RJM Programming
// February, 2022
// Make apple_script_url.php useful

var firstloc='HTTP://localhost:8888/';
var locfound=false;
var asuwo=null;
var defleft='' + eval(-30 + eval('' + screen.width));
var deftop='50';
var defcssleft='calc(100% - 30px)';
var defcsstop='50px';
var cssoverriders='';
var emojin='128221';
var mustcontainc=('' + document.URL + '.').substring(0,1);


function justplayme() {
if (locfound) {
if (('' + document.URL).indexOf(mustcontainc) != -1) {
asuwo=window.open(firstloc + 'apple_script_url.php?justplay=y&showothers=y&tsplus=' + encodeURIComponent(document.URL.split('#')[0].replace('HTTP','http').replace(/\./g,'_').replace(/\?/g,'_').replace(/\&/g,'_').replace(/\=/g,'_').replace(/\:/g,'_').replace(/\//g,'_')) + '&url=' + encodeURIComponent(document.URL.split('#')[0]),'_blank','top=50,left=50,width=50,height=50');
setTimeout(checkasu, 5000);
}
}
}

function checkasu() {
if (asuwo.closed) { // local web server there
if (!locfound) {
document.body.innerHTML+='<style> #asue { position:fixed; left:' + defcssleft + '; top:' + defcsstop + '; z-index:99; cursor:pointer; ' + cssoverriders + ' } </style><div onclick=justplayme(); title="Apple Script snapshot re-execution via macOS Desktop" id=asue>&#' + emojin + ';</div>';
}
locfound=true;
asuwo=null;
} else {
locfound=false;
asuwo.close();
asuwo=null;
}
}

function changethedefaultsmaybe() {
var defpallette='', thisonepal='', calcpal='', calcper='', icalcper=-1;
if (document.head.innerHTML.indexOf('apple_s' + 'cript_url.js?') != -1) {
defpallette=document.head.innerHTML.split('apple_s' + 'cript_url.js?')[1].split('>')[0].split('"')[0].split("'")[0].replace(/\&\;/g,'&').replace(/mustcontain\=\&$/g, 'mustcontain=' + encodeURIComponent('&')).replace('mustcontain=&&', 'mustcontain=' + encodeURIComponent('&') + '&').replace('mustcontain=&#', 'mustcontain=' + encodeURIComponent('&') + '#');
if (defpallette.toLowerCase().indexOf('mustcontain=') != -1) {
mustcontainc=decodeURIComponent(defpallette.toLowerCase().split('mustcontain=')[1].split('&')[0]);
if (mustcontainc.trim() == '') { mustcontainc=('' + document.URL + '.').substring(0,1); }
}
if (defpallette.toLowerCase().indexOf('left=') != -1) {
thisonepal=decodeURIComponent(defpallette.toLowerCase().split('left=')[1].split('&')[0].replace(/\%$/g,'%25').replace(/\%\ /g,'%25%20').replace(/\%\+/g,'%25%2b').replace(/\%\-/g,'%25%2d').replace(/\%\)/g,'%25%29').replace(/\ /g,'%20').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\+/g,'%2b').replace(/\-/g,'%2d'));
if (thisonepal.indexOf('calc(') != -1 || thisonepal.indexOf('vx') != -1 || thisonepal.indexOf('%') != -1 || thisonepal.indexOf('px') != -1) {
defcssleft=thisonepal;
calcpal=thisonepal.replace(/calc/g,'').replace(/px/g,'').replace(/vx/g,'%');
calcper='';
if (calcpal.indexOf('%') != -1) { icalcper=eval(-1 + eval('' + calcpal.indexOf('%'))); while (calcpal.substring(icalcper,eval(1 + icalcper)) >= '0' && calcpal.substring(icalcper,eval(1 + icalcper)) <= '9') { calcper=calcpal.substring(icalcper,eval(1 + icalcper)) + calcper; icalcper--; } calcpal=calcpal.replace(calcper + '%', '' + eval(eval('' + calcper) * eval('' + screen.width) / 100)); }
calcper='';
if (calcpal.indexOf('%') != -1) { icalcper=eval(-1 + eval('' + calcpal.indexOf('%'))); while (calcpal.substring(icalcper,eval(1 + icalcper)) >= '0' && calcpal.substring(icalcper,eval(1 + icalcper)) <= '9') { calcper=calcpal.substring(icalcper,eval(1 + icalcper)) + calcper; icalcper--; } calcpal=calcpal.replace(calcper + '%', '' + eval(eval('' + calcper) * eval('' + screen.width) / 100)); }
calcper='';
if (calcpal.indexOf('%') != -1) { icalcper=eval(-1 + eval('' + calcpal.indexOf('%'))); while (calcpal.substring(icalcper,eval(1 + icalcper)) >= '0' && calcpal.substring(icalcper,eval(1 + icalcper)) <= '9') { calcper=calcpal.substring(icalcper,eval(1 + icalcper)) + calcper; icalcper--; } calcpal=calcpal.replace(calcper + '%', '' + eval(eval('' + calcper) * eval('' + screen.width) / 100)); }
defleft=eval('' + calcpal);
}
}
if (defpallette.toLowerCase().indexOf('top=') != -1) {
thisonepal=decodeURIComponent(defpallette.toLowerCase().split('top=')[1].split('&')[0].replace(/\%$/g,'%25').replace(/\%\ /g,'%25%20').replace(/\%\+/g,'%25%2b').replace(/\%\-/g,'%25%2d').replace(/\%\)/g,'%25%29').replace(/\ /g,'%20').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\+/g,'%2b').replace(/\-/g,'%2d'));
if (thisonepal.indexOf('calc(') != -1 || thisonepal.indexOf('vh') != -1 || thisonepal.indexOf('%') != -1 || thisonepal.indexOf('px') != -1) {
defcsstop=thisonepal;
calcpal=thisonepal.replace(/calc/g,'').replace(/px/g,'').replace(/vh/g,'%');
calcper='';
if (calcpal.indexOf('%') != -1) { icalcper=eval(-1 + eval('' + calcpal.indexOf('%'))); while (calcpal.substring(icalcper,eval(1 + icalcper)) >= '0' && calcpal.substring(icalcper,eval(1 + icalcper)) <= '9') { calcper=calcpal.substring(icalcper,eval(1 + icalcper)) + calcper; icalcper--; } calcpal=calcpal.replace(calcper + '%', '' + eval(eval('' + calcper) * eval('' + screen.height) / 100)); }
calcper='';
if (calcpal.indexOf('%') != -1) { icalcper=eval(-1 + eval('' + calcpal.indexOf('%'))); while (calcpal.substring(icalcper,eval(1 + icalcper)) >= '0' && calcpal.substring(icalcper,eval(1 + icalcper)) <= '9') { calcper=calcpal.substring(icalcper,eval(1 + icalcper)) + calcper; icalcper--; } calcpal=calcpal.replace(calcper + '%', '' + eval(eval('' + calcper) * eval('' + screen.height) / 100)); }
calcper='';
if (calcpal.indexOf('%') != -1) { icalcper=eval(-1 + eval('' + calcpal.indexOf('%'))); while (calcpal.substring(icalcper,eval(1 + icalcper)) >= '0' && calcpal.substring(icalcper,eval(1 + icalcper)) <= '9') { calcper=calcpal.substring(icalcper,eval(1 + icalcper)) + calcper; icalcper--; } calcpal=calcpal.replace(calcper + '%', '' + eval(eval('' + calcper) * eval('' + screen.height) / 100)); }
deftop=eval('' + calcpal);
}
}
if (defpallette.toLowerCase().indexOf('css=') != -1) {
cssoverriders=decodeURIComponent(defpallette.toLowerCase().split('css=')[1].split('&')[0].replace(/\%$/g,'%25').replace(/\%\ /g,'%25%20').replace(/\%\+/g,'%25%2b').replace(/\%\-/g,'%25%2d').replace(/\%\)/g,'%25%29').replace(/\ /g,'%20').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\+/g,'%2b').replace(/\-/g,'%2d'));
}
if (defpallette.toLowerCase().indexOf('emoji=') != -1) {
emojin=decodeURIComponent(defpallette.toLowerCase().split('emoji=')[1].split('&')[0].replace(/\%$/g,'%25').replace(/\%\ /g,'%25%20').replace(/\%\+/g,'%25%2b').replace(/\%\-/g,'%25%2d').replace(/\%\)/g,'%25%29').replace(/\ /g,'%20').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\+/g,'%2b').replace(/\-/g,'%2d').replace(/\,/g,'%2c').replace(/\./g,'%2e').replace(/\:/g,'%3a').replace(/\;/g,'%3b')).replace(/^\&\#/g,'').replace(/\;$/g,'').replace(/\,/g,';&#').replace(/\./g,';&#');
}
}
}


if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
changethedefaultsmaybe();
asuwo=window.open(firstloc + 'apple_script_url.php?imagetest=apple_script_url_test.jpg','_blank','top=' + deftop + ',left=' + defleft + ',width=50,height=50');
setTimeout(checkasu, 2000);
}

More integration awaits!


Previous relevant PHP Calls macOS Apple Script Integration Tutorial is shown below.

PHP Calls macOS Apple Script Integration Tutorial

PHP Calls macOS Apple Script Integration Tutorial

Building on yesterday’s PHP Calls macOS Apple Script Primer Tutorial we want to integrate yesterday’s start onto the recent …

… as macOS (perhaps MAMP local Apache/PHP/MySql web server) “Intranet style” integrations using the two lynchpins …

… leading to a top right 📝 emoji button accessing these Apple Scripts saved over at the macOS system’s “home Desktop” folder, ready for ongoing recall and extending. Is this an intersessional (macOS or Mac OS X only) feeling piece of functionality that interests you? Well, get downloading (and perhaps) tweaking, to find out!


Previous relevant PHP Calls macOS Apple Script Primer Tutorial is shown below.

PHP Calls macOS Apple Script Primer Tutorial

PHP Calls macOS Apple Script Primer Tutorial

Yesterday’s Apple Script Execution of Start Word Suggestions for Wordle Tutorial struck a chord of interest for us. Its use of …

  • macOS command line via Terminal application …
  • Apple Scripting … and …
  • “open” command on that command line

    … opens the door to an idea we’ve wondered about before … perhaps involve multiple web browser “brands” in a single …

    • web application
    • command line application
    • curl web application

    … using … you guessed it … PHP in (what we see as) its 3 modes of use.

    Here’s our first draft of apple_script_url.php we want you to download to (the Document Root of) a macOS MAMP local Apache/PHP/MySql web server environment, ideally, though you can tailor for another macOS local web server arrangement, perhaps …


    <?php
    // apple_script_url.php
    // RJM Programming
    // February 2022

    $ts=date('_dmY_his', time());

    if (isset($argc)) {
    if (PHP_OS == "Darwin") {
    if ($argc >= 2) {
    if (file_exists(getenv('HOME') . '/Desktop/MyAppleScript' . $ts . '.scpt')) {
    unlink(getenv('HOME') . '/Desktop/MyAppleScript' . $ts . '.scpt');
    }
    file_put_contents(getenv('HOME') . '/Desktop/MyAppleScript' . $ts . '.scpt', "tell application \"Terminal\"\n activate\n do script \"cd '" . getenv('HOME') . '/Desktop' . "'\" in window 1\n do script \"open '" . $argv[1] . "'\" in window 1\nend tell");
    exec("cd " . getenv('HOME') . '/Desktop ; open MyAppleScript' . $ts . '.scpt');
    }
    }
    } else if (isset($_GET['url'])) {
    if (PHP_OS == "Darwin") {
    if (file_exists(getenv('HOME') . '/Desktop/MyAppleScript' . $ts . '.scpt')) {
    unlink(getenv('HOME') . '/Desktop/MyAppleScript' . $ts . '.scpt');
    }
    file_put_contents(getenv('HOME') . '/Desktop/MyAppleScript' . $ts . '.scpt', "tell application \"Terminal\"\n activate\n do script \"cd '" . getenv('HOME') . '/Desktop' . "'\" in window 1\n do script \"open '" . str_replace('+','%20',$_GET['url']) . "'\" in window 1\nend tell");
    //exec('open \"' . getenv('HOME') . '/Desktop/MyAppleScript' . $ts . '.scpt\"');
    passthru("cd " . getenv('HOME') . '/Desktop ; open MyAppleScript' . $ts . '.scpt');
    } else if (strpos($_SERVER['SERVER_NAME'], 'localhost') === false) {
    echo "<html><body onload=\" window.open('HTTP://localhost:8888/apple_script_url.php?url=" . str_replace('+','%20',$_GET['url']) . "','_self'); \"></body></html>";
    }
    }
    ?>

    … and if you have downloaded, you may get some joy with it calling Google into a new web browser arrangement via the pressing of an Apple Script window Play button … or … get to the macOS Terminal prompt and type …


    php /Applications/MAMP/htdocs/apple_script_url.php https://google.com

    … or …


    curl "HTTP://localhost:8888/apple_script_url.php?url=https://google.com"

    If this was interesting you may be interested in this too.


    If this was interesting you may be interested in this too.


    If this was interesting you may be interested in this too.


    If this was interesting you may be interested in this too.


    If this was interesting you may be interested in this too.


    If this was interesting you may be interested in this too.


    If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Games, Operating System, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *