New Section with the best Safari Extensions


(Just double click and it will run)

Put back all items in the Trash

In the Latest version of Mac OS X, apple introduced the "put back" element in the context menu. When you delete a file, its original position is stored in the DsStore hidden file in case you want to restore it. The only problem is that it lets you do it for only one item at the time. Just today I accidentally moved to the trash 10k files from different folders (done via a search) and found myself with this problem. I researched for some time but found no one of coming around this so I decided to write an Applescript workaround on my own.

Here is the code:

tell application "System Events"
	tell process "Finder"
		repeat 100 times
			tell application "Finder" to open trash
			tell application "Finder" to activate
			key code 126
			key down command
			key code 51
			key up command
			delay 0.2 -- adjust delay as needed
		end repeat
	end tell
end tell
tell application "Finder" to close every window

Empty Names

For some strange reason the Address Book application doesn't let you you create a smart group or search all contacts with an empty "first name" which is a basic feature in order to maintain thing neat. How many times did you waste time looking for a contact because there were errors with it's fields? All this script does is place all the your contacts with no "First Name" set int he group "My Group". Now you can see which ones they are and modify if you desire. This is an important step for the next script.

Here is the code:

tell application "Address Book"
	set thePeople2 to every person
	set theGroup to make new group with properties {name:"My Group"}
	repeat with i from 1 to count of thePeople2
		set thePerson to (item i of thePeople2)
		if not (image of thePerson exists) then
			add thePerson to group "My Group"
		end if
	end repeat
end tell

Split Last Name

I found a greasemonkey script for firefox (although I prefer Safari) that lets you download the contacts from your facebook friends. The problem is that once I imported it to my Address Book, the full name was inserted in the "Last Name" field (yes, I'm a precision freak). Therefore the "First name would be empt and the "Last Name" John Doe. What this script does is get all the people in the group "My Group" (created from the script above; you can easily edit it to whatever you like) and split the last name. FYI this takes the first part of the last name field and places it in the first name field. If a contact has a middle name, it will remain in the last name field; you have to do it manually since the computer can't distinguish between middle names and double last names.

Here is the code:

tell application "Address Book"
set first name to first word in first name     
set last name to last word in first name
set the thePeople to (every person in group "My Group")
repeat with i from 1 to count of thePeople	
set theirName to (last name of (item i of thePeople))	
set firstName to (first word of theirName)	
set lastName to (last word of theirName)
set properties of (item i of thePeople) to {first name:firstName, last name:lastName}
set newFirstName to (first name of (item i of thePeople))
set newLastName to (last name of (item i of thePeople))
end repeat
end tell


This is one of the best script I wrote... I wanted to send holiday greeting to everyone in my address book with an photo I took but still personalize it with the recipient's name, some text and my custom signature. I searched a lot on the internet but found no one able to put all fo this together (some were without image, others without signature and so on. What this script does is basically email a the people you have selected (highlighted) in your address book the same message. It will prompt you for a subject, a text and a filename in case you want to attach something (a photo, a pdf, song etc). The opening line will be something like "This one is for you first_name_of_contact,". It is a script therefore runs very fast. However, I would advise running it with selection of around 10 people per time for optimal results (and to make sure you don't include people you shouldn't.... ;)

Here is the code:

set targetFileName to "/Users/yourName/Desktop/Xmas-card2.jpg"
set targetFileName2 to "/Users/yourName/Desktop/Wallpaper.jpg"
set MySubject to "Greetings from xxx"
set msg to "Attached you will also find a picture of Christmas here in Tuscany"
set msg to msg & " that you can use as wallpaper to get in the spirit! Happy Holidays!"

tell application "Address Book"
	set thePeople to selection
	set fine to get number of items in thePeople
	set num to "1"

		set indirizzo to value of first email of (item num in thePeople) as text
		set tizio to (first name of (item num in thePeople))
		set greeting to "This is for you " & tizio & ","
		set body to greeting & return & return & msg & return
	tell application "Mail"
			set this_message to make new outgoing message
			set visible of this_message to true
			set content of this_message to body
			set subject of this_message to MySubject
			set message signature of this_message to signature "yourSavedSignature" of application "Mail"
			tell this_message
				make new to recipient at beginning of to recipients with properties {address:indirizzo}
			end tell
			tell content of this_message
				make new attachment with properties {file name:targetFileName} at after the the fourth paragraph
			end tell
			tell content of this_message
				make new attachment with properties {file name:targetFileName2} at after the last paragraph
			end tell
			send this_message
		end tell

		set num to num + 1
		if num = fine + 1 then exit repeat

	end repeat
end tell

Relocate featuring

How many times were you browsing or searching your iTunes/iPod library and felt annoyed by the non consistent formatting of the various tracks with "features"? I certainly did and this morning decided to write a script to fix it. It really made my day... what it does, is get all the tracks that contain "feat" or "ft" and moves that part to the title so that everything is in place.

Here is the code:

tell application "iTunes"
	set liste to {" (feat", " (ft", " feat", " ft"}
	repeat with stringa in liste
		make new playlist with properties {name:stringa}
		set brani to (every track whose artist contains stringa)
		repeat with brano in brani
			duplicate brano to playlist stringa
		end repeat
	end repeat

	repeat with stringa in liste
		repeat with canzone in (every track of playlist stringa)

			set char to offset of stringa in (get artist of canzone)
			set tot2 to text char thru -1 of (get artist of canzone)
			set titolorig to (get name of canzone)
			set final to titolorig & tot2
			set name of canzone to final

			set char2 to char - 1
			set tot2 to text char2 thru 1 of (get artist of canzone)
			set artist of canzone to tot2
		end repeat
	end repeat

	repeat with stringa in liste
		delete playlist stringa
	end repeat
end tell

For any help with these scripts or having custom ones

just get in touch: giacomoballi @