2016-08-13 92 views
1

我试图从我的PHP脚本传递参数给这样的applescript;如何从php exec传递参数到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 

但是苹果脚本没有运行。如果我取出运行argv并设置第一项,脚本将正常运行。我不知道我做错了什么!

+0

不知道,但听起来hinkey。几点思考... 1.请记住,GUI应用程序需要以完整的GUI用户帐户运行,而Apache/PHP通常作为更具限制性的非GUI用户(Web)运行。 2.如果你没有把脚本的完整路径传给osascript,你需要确保在你的'exec()'中设置了正确的工作目录。 3.你是否已经在终端以普通用户的身份测试过你的osascript命令,以确保它在那里正常工作? – foo

+0

您使用的是哪个版本的PHP? – Dekel

回答

0

这是什么像什么,我用它来调用带参数的一个AppleScript文件从PHP脚本:

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