【问题标题】:How to pass arguments from php exec to applescript如何将参数从 php exec 传递给 applescript
【发布时间】:2017-11-19 22:09:56
【问题描述】:

我正在尝试像这样将参数从我的 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 没有运行。如果我取出 run argv 并设置第一项,则脚本可以正常运行。我不确定我做错了什么!

【问题讨论】:

  • 不知道,但听起来很时髦。几个想法…… 1. 请记住,GUI 应用程序需要在完整的 GUI 用户帐户中运行,而 Apache/PHP 通常作为限制性更强的非 GUI 用户(Web)运行。 2. 如果您没有将脚本的完整路径传递给 osascript,则需要确保在 exec() 中设置了正确的工作目录。 3. 您是否以普通用户的身份在终端中测试了您的 osascript 命令,以确保它在那里正常工作?
  • 您使用哪个版本的 PHP?

标签: php applescript


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    相关资源
    最近更新 更多