Last active
          August 29, 2015 14:11 
        
      - 
      
- 
        Save jacobsalmela/d61764ec3394facdebac to your computer and use it in GitHub Desktop. 
    Run terminal-notifier script as root without hanging
  
        
  
    
      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/python | |
| #-----------IMPORTS---------- | |
| import sys,pwd,os | |
| import subprocess | |
| from platform import mac_ver | |
| #----------VARIABLES--------- | |
| v, _, _ = mac_ver() | |
| v = float('.'.join(v.split('.')[:2])) | |
| # Use Casper parameters 4-7 | |
| title = sys.argv[4] | |
| subtitle = sys.argv[5] | |
| message = sys.argv[6] | |
| group = sys.argv[7] | |
| #------------------------------ | |
| #-------BEGIN SCRIPT----------- | |
| #------------------------------ | |
| if (v == 10.9) or (v == 10.10): | |
| u = os.getlogin() | |
| if ( u == '_atsserver') or ( u == 'root'): | |
| print u + " owns the loginwindow--no notification will be sent." | |
| else: | |
| print u + " owns the loginwindow--sending notification..." | |
| pw = pwd.getpwnam(u) | |
| os.initgroups(u,pw.pw_gid) | |
| env={"TERM":"xterm","USER":pw.pw_name,"HOME":pw.pw_dir,"SHELL":pw.pw_shell,"LOGNAME":pw.pw_name,"PATH":"/usr/bin:/bin:/opt/bin"}; | |
| os.setgid(pw.pw_gid); | |
| os.setuid(pw.pw_uid); | |
| os.execve('/Applications/Hopkins Tech Support.app/Contents/MacOS/notifier',["","-title",title,"-subtitle",subtitle,"-message",message,"-group",group],env); | |
| else: | |
| print "Notifications not supported version " + str(v) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment