Created
October 25, 2012 09:31
-
-
Save aitor/3951640 to your computer and use it in GitHub Desktop.
Shitty 3G uninstall software from @nova_media
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
# | |
# This script tries to quit the app configured in app_to_quit in a nice way. | |
# First it checks if it is actually running. | |
# Then it tries to send it a quit apple event. | |
# If it doesn't respond (maybe because it is locked in a modal dialog) | |
# It will tell the User to quit it manually | |
# | |
# Default value - configure to your hearts content | |
app_to_quit = "Vodafone Mobile Broadband" | |
# You can also overide this on the command line | |
import sys | |
if len(sys.argv) > 1: | |
app_to_quit = sys.argv[1] | |
def call(command_sequence): | |
if sys.hexversion < 0x020500f0: | |
# this is for Tiger (Python 2.3.5) | |
print "nice_quit: script in tiger mode" | |
import popen2 | |
return popen2.Popen3(command_sequence).wait() | |
else: | |
# this is available since python 2.5 (Leopard and above) | |
print "nice_quit: script in leopard mode" | |
import subprocess | |
return subprocess.Popen(command_sequence).wait() | |
def switch_back_to_user(): | |
import os | |
if 0 == os.geteuid(): | |
os.seteuid(os.getuid()) | |
def is_app_running(): | |
return 0 == call(["/usr/bin/killall", "-dc", app_to_quit]) | |
def try_to_quit_app_and_wait(): | |
apple_script = """tell application "%s" \n activate\n quit\n end tell""" % app_to_quit | |
call(["/usr/bin/osascript", "-e", apple_script]) | |
# In theory it should be gone by now, but I saw once that | |
# the first check after this still showed it running. :-( | |
import time | |
time.sleep(1) | |
def tell_user_about_it(): | |
apple_script = """ | |
set my_file to POSIX path of "<ICON_FILE_PATH>" | |
set icon_file to (POSIX file my_file) as alias | |
tell application "System Events" | |
activate | |
display dialog "<VMB_IS_RUNNING>" buttons {"<VMB_BUTTON_NAME>"} default button 1 with icon icon_file with title "<VMB_UNINSTALLER>" | |
end tell | |
""" | |
call(["/usr/bin/osascript", "-e", apple_script]) | |
if __name__ == "__main__": | |
if is_app_running(): | |
switch_back_to_user() | |
try_to_quit_app_and_wait() | |
while is_app_running(): | |
tell_user_about_it() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment