Applescript 隐藏应用程序/别名

Applescript 隐藏应用程序/别名

我正在尝试使用 Automator 中的 Applescript 编写一个应用程序,该应用程序在运行 Sierra 的 Mac Air 的终端上运行。使用该应用程序的帐户已设置家长控制,但我需要授予他们访问终端的权限才能运行该应用程序。最终,我们不希望帐户上的用户访问终端。因此,我正在尝试找出删除或隐藏别名的方法。

我能够使用下面的脚本删除别名,但是当他们再次尝试使用该应用程序时,它不起作用,因为终端不再可用:

tell application "System Events" to delete alias "/Path/to/Library/Managed Items/My Applications/Terminal"
end tell

当我尝试隐藏别名时,如下所示,我收到一条错误,指出该过程不能设置为 false:

tell application "System Events" 
        set visible of application process "/Path/to/Library/Managed Items/My Applications/Terminal" to false
end tell

不确定是否可以在脚本开始时加载终端,然后在结束时删除它,或者是否有办法隐藏别名。

任何建议将不胜感激!!

这是我的全部代码:

on run {input, parameters}

tell application "System Events"
    key code 21 using option down
end tell --used to deactivate trackpad

tell application "Terminal"
    activate
    tell application "Terminal"
    do script "su <admin account>" --not root
    delay 2
    tell application "System Events"
        keystroke "<password>" & return
        delay 2
        keystroke "sudo kextunload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/" & return --used to disable keyboard
        delay 2
        keystroke "<password>" & return
        delay 2
        keystroke "exit" & return
        delay 2
        tell application "Terminal"
            do script with command "rm -R release.zip; rm -R release; wget https://URL/for/webserver/release.zip; unzip release.zip; rm -rf __MACOSX" in window 1 --deletes old configuration .zip file and folder; downloads new configuration files; unzips new configuration files
            delay 15
        end tell
        tell application "Terminal"
            do script with command "su <admin account>" in window 1
            delay 2
            tell application "System Events"
                keystroke "<password>" & return
                delay 2
                keystroke "sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/" & return --reloads keyboard
                delay 2
                keystroke "exit" & return
                delay 2
            end tell
            tell application "Terminal"
                do script with command "release/pc-release-mac.command --config config.properties; exit" in window 1 --Launches print release software
            end tell
        end tell
    end tell
    delay 2
    tell application "Terminal"
        quit
    end tell
end tell
end tell
end tell

tell application "System Events"
    key code 21 using option down
end tell --reactivates trackpad

return input
end run

任何改进都将不胜感激!我是脚本新手,所以我对大部分内容都感到困惑。

答案1

如果您在 AppleScript 中使用“do Shell script”命令,则该命令将在不启动终端的情况下执行。这里有一个“do shell script”AppleScript 示例供您试用。请注意,终端永远不会启动。

display dialog (do shell script "curl ifconfig.co") with icon 2 buttons "OK" default button 1 with title "Your Current IP Address Is.." giving up after 5

答案2

在阅读了 8bittree 和 wch1zpink 发表的评论后,我决定研究使用 Applescript 来运行 shell 脚本。我能够在不需要终端的简单脚本中获得我需要的一切。在尝试使用 shell 脚本之前,我的问题是我将默认脚本留在了窗口中。在我删除它之后,下面的代码完全满足了我的需要:

do shell script "rm -R /Users/<account>/release.zip; rm -R /Users/<account>/release; curl -L https://URL/to/webserver/release.zip -o /Users/<account>/release.zip; unzip -o /Users/<account>/release.zip -d /Users/<account>; rm -rf /Users/<account>/__MACOSX; /Users/<account>/release/pc-release-mac.command --config config.properties"

不需要终端;不需要禁用键盘;不需要禁用触控板;不需要硬编码密码。

谢谢你们给我指明方向!!!

相关内容