Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Help With Applescript

Im having trouble making this applescript work. Im trying to get it to detect an app runing and then send an email along with quiting the app and displaying a dialog. It also does not detect apps not downloaded from the app store. Any help is greatly appreciated


Here is the script


tell (get system info)

set longName to long user name

set shortName to short user name

end tell


set badApps to {"Messages", "Safari"}


repeat


repeat with badApp in badApps

if application badApp is running then

tell applicationbadApp to quit

display dialog "The Game " & badApp & " is not allowed during school hours please report to I.T. by the end of the day. A log of your activities has also been sent to I.T." buttons {"Report To I.T."} default button 1 cancel button 1 with title "Gaming Alert" with icon stop

end if

end repeat

end repeat

repeat with badApp in badApps

if application badApp is running then

tell application "Mail"

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

tell theNewMessage


makenewto recipientat end of to recipientswith properties {address:"example@example.com"}

send

end tell

end tell

end if

end repeat

end

return 10

MacBook, Mac OS X (10.7.2), Using iTunes

Posted on Oct 22, 2013 5:25 PM

Reply
Question marked as Best reply

Posted on Oct 22, 2013 6:02 PM

It would help if you mentioned specifically what is not working. Just looking at your posted script I can see that it will not send an email - since you have already quit the offending application in your first dialog loop, it won't be running when the second loop looks for it.


I'm not sure why an application from the App Store would behave differently, but you might try targeting the application by its bundle identifier - this will also work if the application name is changed.

1 reply
Question marked as Best reply

Oct 22, 2013 6:02 PM in response to steve's assistant

It would help if you mentioned specifically what is not working. Just looking at your posted script I can see that it will not send an email - since you have already quit the offending application in your first dialog loop, it won't be running when the second loop looks for it.


I'm not sure why an application from the App Store would behave differently, but you might try targeting the application by its bundle identifier - this will also work if the application name is changed.

Help With Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.