getting height x width of image
getting height x width of image
- Subject: getting height x width of image
- From: TjL <email@hidden>
- Date: Wed, 20 Jun 2007 14:44:31 -0400
Warning: I know almost nothing about Applescript except what I've
learned from looking at the occasional tip @ macosxhints etc.
BACKGROUND:: What I have managed to do thus far: I created a Folder
Action so that when I take a screenshot (cmd+shift+4) and it creates
a file ~/Desktop/Picture 1.png then the Folder Action will
1) Rename it to have a unique filename based on the date/time it was
taken
2) move it to ~/Pictures/
3) open the picture in Preview.app
so, for example, a recent screenshot was renamed from ~/Desktop/
Picture 1.png to ~/Pictures/screenshot-2007-06-20_14.39.57.png
BUT NOW I want to do something else. I would like to add the height-
x-width of the image to the filename so that it would look like this:
screenshot-344x208-2007-06-20_14.39.57.png
Here's what I have. It doesn't work now that I have added the Image
Events stuff. It just leaves the ~/Desktop/Picture 1.png as is. No
error message is given.
NOTE: the bulk of the below was stolen from a hint at macosxhints,
it's not my original work... except for the "Image Events" part --
which doesn't work
on adding folder items to this_folder after receiving added_items --
folder action handler
set theDate to do shell script "/bin/date \"+%Y-%d-%m_%H.%M.%S\"" --
get the date string
-- is there a better way to get the date w/o using a shell script?
set thePicturePath to path to pictures folder from user domain --get
the full path to your pictures folder
set theMusicPath to path to music folder from user domain --get the
full path to your music folder
repeat with x in added_items
--you always get a list, even if it's one file, so we loop through
the list here
set theFile to x --x is just a list placeholder, let's use a better
name for what x refers to
tell application "Finder" --since we're manipulating files, we use
the Finder
set theName to the name of theFile --get the full name, including
the extension
if theName starts with "Picture" then
--since this runs automatically, we want to make sure we ONLY get
screenshots
set theFileExtension to name extension of theFile
--preserve the extension, whatever it is. This doesn't include
the dot
try
tell application "Image Events"
-- start the Image Events application
launch
-- open the image file
set theFile to open theFile
-- get dimensions of the image
copy dimensions of theFile to {W, H}
end tell
on error error_message
display dialog error_message
end try
set the name of theFile to "screenshot-" & W & "x" & H & "-" &
theDate & "." & theFileExtension
tell application "Preview" to open theFile --open the new file in
Preview
move theFile to thePicturePath
--rename the file with the date, and the proper file extension
--set theNewFile to duplicate theFile to thePicturePath with
replacing
--we actually copy the file to the Pictures folder, so it's
nondestructive
--in case something goes wrong. this will leave the original on
your desktop
end if
if theName starts with "message" then
--since this runs automatically, we want to make sure we ONLY get
voicemail messages
set theFileExtension to name extension of theFile
--preserve the extension, whatever it is. This doesn't include
the dot
set the name of theFile to "voicemail-" & theDate & "." &
theFileExtension
--rename the file with the date, and the proper file extension
tell application "QuickTime Player" to open theFile --open the
new file in QuickTime
move theFile to theMusicPath
-- THE BELOW was the original code, which was safer but sloppy
-- as it left a copy of the file on the Desktop
--we actually copy the file to the Music folder, so it's
nondestructive
--in case something goes wrong. this will leave the original on
your desktop
-- set theNewFile to duplicate theFile to theMusicPath with
replacing
end if
end tell
end repeat
end adding folder items to
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden