Page 1 of 1

Sort Skype downloads by user name

PostPosted: Tue Mar 06, 2012 8:48 am
by Farthen
Hi,

I use Skype a lot (basically because there are so many people who don't use Jabber but whatever). If you set Skype.app to download files to one fixed folder it throws all the files in there. I'd like to sort them by user name though. As Skype doesn't have an option for that I created a Hazel rule for that :)

First you need to set Skype to download your files in one fixed folder: Image

Now let's create the Hazel rule for that. Add the folder you just set in Skype. Then create a new rule. Select "other" for the conditions and select "Where from", set it to "is not blank". Skype always sets the "Where from" attribute on the files to some string containing the user name and some garbage.
Image

Now to the actions part: Add a "Run AppleScript" action and paste the following script:
Code: Select all
tell application "System Events" to set filename to the POSIX path of theFile
set theUsername to do shell script "mdls -name kMDItemWhereFroms -raw \"" & filename & "\" | tr -d \"\\015\" | sed -n -e 's/^.*\\\"\\(.*\\) *(.*)\\..*Skype.*$/\\1/p' | sed -e 's/^ *//' -e 's/ *$//' -e 's/\\n//'"
return {hazelExportTokens:{skypeUsername:theUsername}}


Click the i button and add a token called "skypeUsername": Image

Add another action and set it to "sort into subfolder". Click the pattern editor and drag "skypeUsername" in the text field.
Image

Set the options to "If file exists: rename", close the rule, run it and watch how the magic happens :)

Let me know if this works if you have set Skype to a different language setting. I don't see a reason why it shouldn't but I only tested this with the German version. (and only changed my language to make the screenshots for this)

Re: Sort Skype downloads by user name

PostPosted: Tue Mar 06, 2012 1:30 pm
by Mr_Noodle
Neat. I'm glad people are making use of the new token export feature.

Re: Sort Skype downloads by user name

PostPosted: Tue Mar 06, 2012 2:30 pm
by Farthen
Yeah, it's a very nice feature to enable scripts to just modify / retrieve values and somehow return them to Hazel. Before shell scripts were like some kind of one-way thing. Fire and forget, no way to return anything :)