Pages

Sunday, June 16, 2013

Re: Need Help With Apple Script

  1. You didn't provide any information about the error, so I can't verify it since I don't have MineCraft to test.  I can't see any reason off hand why the application would hang, although your script will wait until the dialog is dismissed before continuing with the rest of the script.
  2. As hinted to above, you will need to quit the applications and send the email before putting up the dialog, since the script/application will wait while the dialog is up.
  3. Just add other application names to check for.
  4. To use other email clients you will need to use whatever scripting commands or other API they provide.

 

The following script application should combine your previous examples and allow for multiple applications - save it as a stay-open application.  You should also add a LSUIElement key set to true in the application Info.plist so that it doesn't show a menu or appear in the Dock.

 

 

property illegalApps : {"MineCraft"} -- add application names as needed

property longName : missing value

property shortName : missing value

 

on run -- setup

  tell (get system info)

    set longName to long user name -- for use in the email message

    set shortName to short user name -- for use in the shell script

  end tell

end run

 

on idle -- repeatedly executes after the run handler completes

  tell application "System Events" to set appList to get name of processes whose background only is false

  set editedList to {}

  repeat with anApp in appList -- filter for illegal apps

    set anApp to contents of anApp

    if anApp is in illegalApps then set end of editedList to anApp

  end repeat

  if editedList is not {} then notifyAndQuit(editedList) -- illegals found

  return 60 -- do it again in 60 seconds

end idle

 

on notifyAndQuit(quitList)

  tell application "Mail" -- send mail

    set theNewMessage to make new outgoing message with properties {subject:"Gaming Alert [" & longName & "]", content:"[" & longName & "] has been gaming, he is to report to I.T. by the end of the day", visible:true}

    tell theNewMessage

      make new to recipient at end of to recipients with properties {address:"itdesk@blahblahblah.net"}

      send

    end tell

  end tell

 

  repeat with anApp in quitList -- kill user processes with extreme prejudice

    do shell script "killall -9 -u " & shortName & " -c " & quoted form of anApp

  end repeat

 

  activate me

  display dialog "Gaming is not allowed, Your log of your computer programs running has been emailed to the I.T. department. Please visit the I.T. department immedietly to remove this message" buttons {"Report To I.T."} default button 1 with title "Gaming Alert" with icon stop

end notifyAndQuit



View the original article here

0 comments:

Post a Comment