Tag Archive: applescript


Delicious Library and Me

I’ve been cataloguing a lot of stuff that I have with a view to selling it. Having got the new mac I checked to see if my code for delicious library still worked, which it did. Since then I’ve realised that what I also need is a searchable index for the ammo box type things full of CD’s. Currently they’re in there with the CD in the front of the slip and the inlays in the back. A lot of these are scanned in already or I’m scanning them in as I go.
Delicious Library has a ‘location’ field which is blank by default and only shows up when you edit an item. I needed to set this for things as I went so I created this small applescript:

-- Menu Title: [3] "Set Location"
-- Menu Keyboard Shortcut: command-l
-- Menu Path: [3]

-- Copy and paste everything into Script Editor (use spotlight to find it).
-- Then save to home/Library/Scripts/Applications/Delicious Library 2
-- You can edit the menu keyboard shortcut to be whatever you want.

tell first document of application "Delicious Library 2"
set selectedItems to selected media
set itemsRef to a reference to selectedItems
repeat with mediaItem in itemsRef
display dialog "Enter location:" default answer "X.X"
set newLocation to text returned of result
set location of mediaItem to newLocation
end repeat
end tell

Which does what I want. After I’ve scanned an item in I can hit apple-l and type in the location. Much much faster.

A small applescript utility.

Knocked this up today as I figure it will prove it’s worth in the future. Drag and drop an image onto it and it will generate the necessary files for the various icons/artwork an iPhone/iPhone4 or iPad application, it should work with PNG, JPG and all the usual formats and also for other apps if you have them installed and they support applescript, e.g. photoshop.

-- Receives files and generates the necessary Icons with the correct names/sizes
-- for iPhone/iPhone4 and iPad applications

on open the_images
	repeat with thine_image in the_images
		try
			generate_icons(thine_image)
		end try
	end repeat
end open

(*
set this_image to choose file of type {"JPG", "PNG"}
generate_icons(this_image)
*)

to generate_icons(this_image)
	set oldDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {"."}

	set cur_name to name of (info for this_image) as string
	set basename to first text item of cur_name
	set extension to "." & last text item of cur_name

	try
		tell application "Image Events"
			launch
			-- Open image and resize to 72
			set imageptr to open this_image
			scale imageptr to size 72
			set the props_rec to the properties of imageptr
			set savePath to (path of location of props_rec) & "Icon-72.png"
			save imageptr as PNG in file savePath with icon
		end tell

		tell application "Image Events"
			-- Open image and resize to 50
			set imageptr to open this_image
			scale imageptr to size 50
			set the props_rec to the properties of imageptr
			set savePath to (path of location of props_rec) & "Icon-Small-50.png"
			save imageptr as PNG in file savePath with icon
		end tell

		tell application "Image Events"
			-- Open image and resize to 29
			set imageptr to open this_image
			scale imageptr to size 29
			set the props_rec to the properties of imageptr
			set savePath to (path of location of props_rec) & "Icon-Small.png"
			save imageptr as PNG in file savePath with icon
		end tell

		tell application "Image Events"
			-- Open image and resize to 58
			set imageptr to open this_image
			scale imageptr to size 58
			set the props_rec to the properties of imageptr
			set savePath to (path of location of props_rec) & "Icon-Small@2x.png"
			save imageptr as PNG in file savePath with icon
		end tell

		tell application "Image Events"
			-- Open image and resize to 57
			set imageptr to open this_image
			scale imageptr to size 57
			set the props_rec to the properties of imageptr
			set savePath to (path of location of props_rec) & "Icon.png"
			save imageptr as PNG in file savePath with icon
		end tell

		tell application "Image Events"
			-- Open image and resize to 114
			set imageptr to open this_image
			scale imageptr to size 114
			set the props_rec to the properties of imageptr
			set savePath to (path of location of props_rec) & "Icon@2x.png"
			save imageptr as PNG in file savePath with icon
		end tell

		tell application "Image Events"
			-- Open image and resize to 512
			set imageptr to open this_image
			scale imageptr to size 512
			set the props_rec to the properties of imageptr
			set savePath to (path of location of props_rec) & "iTunesArtwork"
			save imageptr as PNG in file savePath with icon
		end tell

		set AppleScript's text item delimiters to oldDelim
	on error m
		set AppleScript's text item delimiters to oldDelim
		log ("GENERAL ERROR: " & m)
		return false
	end try
end generate_icons

It’s worth noting the following warnings:

- It’s not efficient.
- It’s dumb, it will overwrite stuff.
- If you drop more than one file you’ll probably only get the last one.

This suits my needs, feel free to alter it to produce other stuff.. for example you should spot the basename and extension stuff so savePath could become:

set savePath to (path of location of props_rec) & basename & "-Icon-72" & extension

You could then make the file type match the original with:

set file_format to imageptr's file type

then edit PNG in the save code to become file_format.

Powered by WordPress | Theme: KLG based on Motion by 85ideas.