Hazel and Google Drive

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hazel and Google Drive Sat Dec 29, 2012 11:16 am • by tsolignani
I use google drive with the local client at work and I would like to set something into Hazel to be notified via mail of some file changes. I know you can use Hazel to send outbound mail with Growl and a plugin, but I just would prefer to stick with the Mountain Lion notification center. So, is there a way to get Hazel to send out mail? Maybe with Mail and Applescript? Thank you.


–
cordialmente,

tiziano solignani, da  Mac
http://blog.solignani.it
tsolignani
 
Posts: 7
Joined: Sat Dec 29, 2012 11:13 am

Re: Hazel and Google Drive Sat Dec 29, 2012 5:37 pm • by a_freyer
Yup - we can use applescript to do this:

Code: Select all
tell application "Mail"
   set theNewMessage to make new outgoing message with properties {subject:"Google Drive File Change Notification", content:"The file: " & theFile & " has beed updated by the client.", visible:true}
   tell theNewMessage
      make new to recipient at end of to recipients with properties {address:"email.address@me.com"}
      send
   end tell
end tell


Use like this:

Code: Select all
if (all) of the following conditions are met for (the file or folder being processed):
     ...

Do the following to the matched file or folder:
     Run AppleScript (embedded script)
     Display Notification
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Hazel and Google Drive Sun Dec 30, 2012 5:55 am • by tsolignani
Thank you. I tried that and it does just work.

Do you or any of you know whether there is a way to get some parameters from the file to the script, such as extension, meta tag, path, else or can you just pass the file name?

Thank you, have a nice Sunday.


–
cordialmente,

tiziano solignani, da  Mac
http://blog.solignani.it
tsolignani
 
Posts: 7
Joined: Sat Dec 29, 2012 11:13 am

Re: Hazel and Google Drive Sun Dec 30, 2012 11:37 am • by a_freyer
You can get tons of information from the file in many different ways. I think the easiest is with the bash tool MDLS, but that's just a personal favorite.

Unfortunately we have to do some awkward (pun?) output tweaking, but its all relatively straightforward. If you want to see the other info available for MDLS, open terminal and run MDLS /path/to/your/file

Code: Select all
set theName to do shell script "mdls -name kMDItemFSName \"" & thePOSIX & "\" | awk -F ' = ' '{print $2}' | sed 's/\\\"//g'"
   
set theKind to do shell script "mdls -name kMDItemKind \"" & thePOSIX & "\" | awk -F ' = ' '{print $2}' | sed 's/\\\"//g'"

tell application "Mail"
   set theNewMessage to make new outgoing message with properties {subject:"Google Drive File Change Notification", content:"The Name: " & theName & "
The Type:" & theKind &"

Was updated by the client.", visible:true}
   tell theNewMessage
      make new to recipient at end of to recipients with properties {address:"email.address@me.com"}
      send
   end tell
end tell



You'll be able to get your meta tags here too, but you'll have to find the item name first.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado


Return to Support