1

I'm trying to pass arguments from my php script to applescript like this;

function runAppleScript(){
    exec("osascript processMail.scpt testing testing1");
}

and receive the first argument in applescript like this;

on run argv
    set trimmedQuery to first item of argv

    tell application "Fake"
        activate
        open "Macintosh HD:Users:mini:Documents:fake workflows:login.fakeworkflow"
        delay 1
        run workflow with variables {inputAddress:trimmedQuery}
        wait until done
        quit

    end tell
end run

But the applescript isn't running. If I take out the run argv and setting the first item, the script runs properly. I'm not sure what I'm doing wrong!

2
  • Dunno, but sounds hinkey. Couple thoughts… 1. Bear in mind that GUI apps need to run in a full GUI user account while Apache/PHP normally runs as a more restrictive non-GUI user (web). 2. If you aren't passing the full path to your script to osascript, you'll need to make sure that the correct working directory is set in your exec(). 3. Have you tested your osascript command in Terminal as a normal user to make sure it works right there? Commented Aug 13, 2016 at 20:40
  • Which version of PHP you use? Commented Aug 14, 2016 at 13:02

1 Answer 1

1

Here is something like what I use to call an AppleScript file with arguments from a PHP script:

PHP:

somefile.php:
#!/bin/php
<?php
    $arg1 = $fname;
    $arg2 = $path;
    $cmd = "osascript example.applescript \"$arg1\" \"$arg2\"";
    $returnval = exec($cmd);

AppleScript:

example.applescript:
on run argv
  set fileNameArg to (item 1 of argv)
  set pathArg to (item 2 of argv)
  -- examples:
  display dialog (item 1 of argv)
  display dialog (pathArg)
  if pathArg is in {{}, {""}, ""} then
    on error
        set filePath to (choose file name with prompt "Where would you like to save the file?" default name fileNameArg default location pathArg) as string
    end try
  end if
  POSIX path of filePath
end run
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.