Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Applescript管理员权限,但*不*运行shell脚本_Applescript_Automator - Fatal编程技术网

Applescript管理员权限,但*不*运行shell脚本

Applescript管理员权限,但*不*运行shell脚本,applescript,automator,Applescript,Automator,我正在尝试使我的Applescript代码具有管理员权限。然而,我通过谷歌搜索找到的唯一解决方案是: do shell script "command" user name "me" password "mypassword" with administrator privileges 我没有运行shell命令。。我用的是纯Applescript。我的代码是: on run {input, parameters} -- copy repeat with aFile in input

我正在尝试使我的Applescript代码具有管理员权限。然而,我通过谷歌搜索找到的唯一解决方案是:

do shell script "command" user name "me" password "mypassword" with administrator privileges
我没有运行shell命令。。我用的是纯Applescript。我的代码是:

on run {input, parameters} -- copy
    repeat with aFile in input
        tell application "Finder"
            if name extension of aFile is "component" then
                copy aFile to "/Library/Audio/Plug-ins/Components" 
            else if name extension of aFile is "vst" then
                copy aFile to "/Library/Audio/Plug-ins/VST"
            end if
        end tell
    end repeat
end run

在使用纯Applescript时,是否仍然可以获得管理员权限?

您的处理程序从运行时的
开始{input,parameters}
,因此我认为我们讨论的是自动化工作流中的执行Applescript步骤。此时,我认为自动机操作总是在当前用户的上下文中执行

但是:当然,您可以在已执行的Applescript操作中使用
do shell脚本
,此时您可以为该do shell调用授予管理员权限。我已按以下方式重建了您的处理程序:

on run {input, parameters} -- copy
    -- collect all resulting cp statements in a list for later use
    set cpCalls to {}

    -- walk through the files
    repeat with aFile in input
        tell application "System Events"
            -- get the file extension
            set fileExt to name extension of aFile
            -- get the posix path of the file
            set posixFilePath to POSIX path of aFile
        end tell
        if fileExt is "component" then
            -- adding the components cp statement to the end of the list
            set end of cpCalls to "cp " & quoted form of posixFilePath & " /Library/Audio/Plug-ins/Components/"
        else if fileExt is "vst" then
            -- adding the vat cp statement to the end of the list
            set end of cpCalls to "cp " & quoted form of posixFilePath & " /Library/Audio/Plug-ins/VST/"
        end if
    end repeat

    -- check if there were files to copy
    if cpCalls ≠ {} then
        -- combine all cp statements with "; " between
        set AppleScript's text item delimiters to "; "
        set allCpCallsInOne to cpCalls as text
        set AppleScript's text item delimiters to ""

        -- execute all cp statements in one shell script call
        do shell script allCpCallsInOne with administrator privileges
    end if  
end run
该操作现在要求提供管理员凭据,但如果愿意,您可以添加
用户名“我”密码“我的密码”

为了避免提示输入每个
cp
的凭据,我收集列表中的所有调用,并在处理程序末尾立即执行它们

你好,迈克尔/汉堡