Search code examples
applescriptquit

is there a way to disable force quit while applescript application is still running?


i made a fake virus to try on my friends :P But i was wondering if there is a code that disables the command-option-escape feature until the application finishes. I just want them to experience the whole process of my experiment without them force quitting it halfway through. Thanks

:edit- It's just a simple script that i thought i could show my friends but i just didn't want them to force quit it after the first few seconds, they still have full control over their mac

display dialog "Play MagroXELA's game" buttons {"Play", "Quit"} default button 1 if the button returned of the result is "Play" then

set volume 5

beep 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

Solution

  • You can also do it this way:

    1. Save the script as application (File > Save and choose as File Format Application) anywhere on your Mac. Then close the AppleScript Editor.

    2. Then navigate to the application in Finder and right click it and choose Show Package Contents

    3. A directory containing the directory Contents will show up. Inside this folder there will be a file named Info.plist

    4. Open this file with your favorite text editor (e.g. TextEdit).

    Then add this code at the end of the file before the last </dict>:

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

    So that the last four lines of the file are looking like this:

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

    Save the file and you're ready to go. You can close the text editor and double click the application.

    This property causes OS X to run the app as background process and background processes don't show up in the Dock and they don't show up in the Force Quit window. Of course you can still force quit the application by using Activity Monitor.

    Be aware of that this property doesn't allow any User Interaction like display dialog or choose folder.

    (If you open the application in the AppleScript Editor you have to repeat this steps because the script editor overrides Info.plist on every save)