Is it possible to use applescripts with encrypted apps?

Started by steven, April 28, 2009, 07:39:09 AM

Previous topic - Next topic

steven

Hello, I really like the app, it's great and does something (encrypt mail) that has been missing for years on the mac. However I am wondering if it is possible to allow applescripts to automatically run and access encrypted apps?

I suspect the answer is no but I thought I'd try. I do not currently use the mail.app due to lack of password protection, and to be honest the only reason I want to use it, is because I can use applescript to do things like show the number of unread messages on my desktop/growl, etc. I currently use a couple applescripts for ical as well.

Here is a simple example that displays new messages (which would then be passed to geektool or growl):

set newline to ASCII character 10
set finalText to ""
tell application id "com.apple.mail"
set unreadCount to (get unread count of inbox)
if unreadCount > 0 then
set theMessages to (messages of inbox whose read status is false)
repeat with i from 1 to number of items in theMessages
set thisMessage to item i of theMessages
set fromMsg to (sender of thisMessage as string)
set subjMsg to (subject of thisMessage as string)
set finalText to finalText & i & ". " & fromMsg & newline & "      " & subjMsg & newline
end repeat
else
set finalText to "No mail."
end if
end tell
finalText

Obviously, if mail.app is unencrypted or already running via espionage login, it works fine. However, if the script is run with mail.app closed, I get an espionage password prompt to unlock mail.app. This is a problem because the script needs to have access so that it can be automated via launchd. Is there any way you can think of to grant a script permission to execute a protected espionage app?

This also seems to be a problem area for iCal/Mail. What I mean is, in iCal you can set an event to email you upon due time. If mail.app is protected, it breaks that function in iCal unless there is some method of granting ical privileges to execute mail.

greg

Hi Steven,

The only problem here is if Mail's folder is locked.  If the folder is unlocked, then whether Mail is running or not does not matter (if the "tell application id "com.apple.mail"" launches mail if it's not already running).

To get this to work first make sure that the script is saved as an "Application Bundle":



Then add it to Mail's application associations, and uncheck "Lock on Quit":



Make sure that it's not run upon login by any means.  If you need it to run at login, then set the "Launch at Login" option for the association in Espionage.

This means that if the script is launched and Mail isn't running, you'll be prompted to enter the password for Mail's folder, Espionage will unlock the folder, and only after the folder is unlocked will it actually allow the script to be run.

Note: I haven't tested your script to check to see if it will launch the Mail app automatically, if it doesn't do this then you'll need to write some code to first launch Mail, wait until it fully launches, and then tell it to do stuff.
Follow @espionageapp@twitter.com or @espionage@mstdn.io for news and updates!

steven

#2
Thank you very much Greg! I must admit I haven't tried this yet but I'll give it a shot and let you know what I think as soon as I have some free time to tinker with this. MY objective is to be able to have my script run automatically via launchd, say every 10min to let me know if I have new email, but I still want to prevent anyone from launching mail.app without entering a password. I don't care if it's not 100% secure, just a basic extra level of password-prompt to prevent a quick "prying eye" from taking a peak at mail.app.

greg

#3
No problem, but if you want the script to run every 10 minutes then I would make sure that it checks to see if Mail is running before attempting to ask it for anything, otherwise you'll get the password prompt.

Also, if you *really* don't care about someone getting access to your email and only want to prevent say, a sister from seeing what's in there, then you can set Espionage to not use any encryption for Mail's folder, in which case you won't need to setup application associations for it.  The application associations are a method of allowing Espionage to delay the launch of an application while it decrypts (mounts) the application's data.
Follow @espionageapp@twitter.com or @espionage@mstdn.io for news and updates!