有没有办法在applescript应用程序仍在运行时禁用强制退出?

时间:2014-09-20 11:11:57

标签: applescript quit

我制作了一个虚假的病毒来试试我的朋友:P但是我想知道是否有一个代码禁用命令选项 - 转义功能,直到应用程序完成。我只是希望他们体验我的实验的整个过程,而不会强迫他们中途退出。感谢

:编辑 - 这只是一个简单的脚本,我以为我可以展示给我的朋友,但我只是不希望他们在前几秒后强制退出它们,他们仍然可以完全控制他们的mac

显示对话框“播放MagroXELA的游戏”按钮{“播放”,“退出”}默认按钮1 如果结果返回的按钮是“播放”,那么

设定第5卷

发出哔哔声5

display dialog "Virus is downloading." buttons "Stop" default button "Stop" with title "Malware Initiating" with icon 2
delay 2
set volume 5
do shell script "say -v Zarvox Virus has Down loaded Successfully"
delay 2
do shell script "say -v Zarvox Wifi terminated"
beep 1
--
-- Toggle Airport Power On and Off
--
if (offset of "On" in (do shell script "networksetup -getairportpower en1")) > 0 then
    do shell script "networksetup -setairportpower en1 off"

end if

tell application "Finder"
    activate
    open application file "Activity Monitor.app" of folder "Utilities" of folder "Applications" of startup disk
    open application file "AirPort Utility.app" of folder "Utilities" of folder "Applications" of startup disk
    open application file "Boot Camp Assistant.app" of folder "Utilities" of folder "Applications" of startup disk
    open application file "Bluetooth File Exchange.app" of folder "Utilities" of folder "Applications" of startup disk
    open application file "Disk Utility.app" of folder "Utilities" of folder "Applications" of startup disk
    open application file "Keychain Access.app" of folder "Utilities" of folder "Applications" of startup disk
    open application file "Terminal.app" of folder "Utilities" of folder "Applications" of startup disk
    open application file "System Information.app" of folder "Utilities" of folder "Applications" of startup disk
end tell


tell application "Finder"
    activate
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    make new Finder window
    set target of Finder window 1 to startup disk
    set target of Finder window 1 to startup disk
    open application file "Terminal.app" of folder "Utilities" of folder "Applications" of startup disk
    set target of Finder window 1 to startup disk
    set target of Finder window 1 to folder "Applications" of startup disk
end tell

delay 6
tell application "DigitalColor Meter" to quit
tell application "Grab" to quit
tell application "Network Utility" to quit
tell application "System Information" to quit
tell application "Terminal" to quit
tell application "Keychain Access" to quit
tell application "Disk Utility" to quit
tell application "Bluetooth File Exchange" to quit
tell application "Boot Camp Assistant" to quit
tell application "AirPort Utility" to quit
tell application "Activity Monitor" to quit
tell application "App Store" to quit
tell application "iTunes" to quit
tell application "Finder"
    repeat while window 1 exists
        close window 1
    end repeat
    delay 2
    set volume 5
    do shell script "say -v Alex YOU GOT TROLLED HUH HUH HUH HUH"
    delay 2
    do shell script "say -v Zarvox Wifi activated"

    --
    -- Toggle Airport Power On and Off
    --
    if (offset of "On" in (do shell script "networksetup -getairportpower en1")) > 0 then
        do shell script "networksetup -setairportpower en1 off"
    else
        do shell script "networksetup -setairportpower en1 on"
    end if
    delay 4

2 个答案:

答案 0 :(得分:2)

你也可以这样做:

  1. 将脚本保存为应用程序(文件>保存并选择为文件格式应用程序),在Mac上的任何位置。然后关闭AppleScript编辑器。

  2. 然后导航到Finder中的应用程序并右键单击它并选择Show Package Contents

  3. 将显示包含目录Contents的目录。在此文件夹中,将有一个名为Info.plist

  4. 的文件
  5. 使用您喜欢的文本编辑器(例如TextEdit)打开此文件。

  6. 然后在文件末尾添加此代码最后</dict>

    <key>LSBackgroundOnly</key>
    <true/>
    

    这样文件的最后四行看起来像这样:

        <key>LSBackgroundOnly</key>
        <true/>
    </dict>
    </plist>
    

    保存文件,您就可以开始了。您可以关闭文本编辑器并双击该应用程序。

    此属性导致OS X作为后台进程运行应用程序,并且后台进程不会显示在Dock中,并且它们不会显示在“强制退出”窗口中。当然,您仍然可以使用Activity Monitor强制退出应用程序。

    请注意,此属性不允许任何用户互动,例如display dialogchoose folder

    (如果您在AppleScript编辑器中打开应用程序,则必须重复此步骤,因为脚本编辑器会在每次保存时覆盖Info.plist)

答案 1 :(得分:1)

您可以使用命令行工具&#34; osascript&#34;执行任何AppleScript代码。运行命令行工具不会显示在强制退出菜单中,因此此方法应该适合您。例如,假设这是你的苹果...

tell application "TextEdit" to activate
delay 5
tell application "TextEdit" to quit

以下是如何使用osascript运行它。

set theCode to "tell application \"TextEdit\" to activate
delay 5
tell application \"TextEdit\" to quit"

do shell script "echo " & quoted form of theCode & " | osascript > /dev/null 2>&1 &"

所以你基本上所要做的就是将你的AppleScript代码转换为文本,然后将其发送到osascript,如图所示。

祝你好运。