如何将参数从php exec传递给applescript

时间:2016-08-13 20:17:02

标签: php applescript

我正试图将我的php脚本中的参数传递给像这样的AppleScript;

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

并像这样收到applescript中的第一个参数;

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

但是AppleScript没有运行。如果我取出运行argv并设置第一项,则脚本可以正常运行。我不确定我做错了什么!

1 个答案:

答案 0 :(得分:1)

这类似于我用PHP脚本中的参数调用AppleScript文件的内容:

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