Re: Image Events
Re: Image Events
- Subject: Re: Image Events
- From: Greg Townsend <email@hidden>
- Date: Fri, 4 Jun 2004 14:55:31 -0400
Thanks, but I still can't get it to work. Here's
what I'm trying to do - it's a script to convert
the artwork for an iTunes track into a PICT file
and thence to a JPEG file. The bulk of it is
copied directly from the conversion example at
the Image Events Appelscript site; I just
substituted the creation of a PICT file from the
iTunes artwork for 'choose file'.
set trackImage to ""
tell application "iTunes"
if data of the artworks of current track exists then
try
set trackImage to data of
front artwork of current track as picture
end try
end if
end tell
if trackImage "" then
set dataFold to path to desktop
set this_file to dataFold & "OldiTunesImage.pict" as string
tell application "Finder"
if (exists of file this_file) = false then
make new file at folder
dataFold with properties
{name:"OldiTunesImage.pict"}
end if
end tell
try
set openFile to open for access
file this_file with write permission
set eof of openFile to 0
write trackImage to openFile starting at eof
close access openFile
on error
try
close access file this_file
end try
end try
--set this_file to choose file
try
tell application "Image Events"
launch
-- get the parent folder of the image file
set the parent_folder to
the container of file this_file
-- derive new name for the new image file
set the new_name to my add_extension(this_file, "jpg")
-- look for an existing file
if (exists file new_name of the parent_folder) then
error "A file
named "" & new_name & "" already exists."
end if
-- open the image file
set this_image to open this_file
-- save in new file. The
result is a file ref to the new file
set the new_image to save this_image as JPEG in ,
file new_name of the parent_folder with icon
-- purge the open image data
close this_image
end tell
tell application "Finder"
-- delete the original file
delete file this_file
end tell
on error error_message
display dialog error_message
end try
end if
on add_extension(this_file, new_extension)
set this_info to the info for file this_file
set this_name to the name of this_info
set this_extension to the name extension of this_info
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to ,
text 1 thru -((length of
this_extension) + 2) of this_name
end if
return (the default_name & "." & the new_extension)
end add_extension
After running the script, no new image file is
created. Thanks again for any help.
Greg
>
If you use the Finder-style of a path then you
>
need to prepend the string with "file", if you
>
use the Posix-style of path then you need to use
>
"Posix path"
>
>
Finder-style path:
>
----
>
tell application "Image Events"
>
open file "path:to:file"
>
end tell
>
----
>
>
Posix-style path:
>
----
>
tell application "Image Events"
>
open Posix file "/path/to/file"
>
end tell
>
----
>
>
- Ken
>
>
On Jun 4, 2004, at 10:59 AM, Townsend, Gregory *HS wrote:
>
>
>I'm having all sorts of trouble with Image
>
>Events, namely that it's not working.
>
>
>
>If I use it to try to information about an
>
>image, I get no information (i.e., an empty
>
>list). I've copied the example scripts at the
>
>AppleScript website just to make sure that I
>
>haven't written something incorrectly, but I
>
>get the same result (or lack thereof).
>
>
>
>I've also tried to use it to convert images. If
>
>I use the scripts at the AppleScript site
>
>exactly, it works ok. However, if I identify
>
>the path to an image file ahead of time rather
>
>than using 'choose file', I get bupkus. I'm
>
>assuming that I must need to use a special
>
>syntax for the path to the image file, but I
>
>can't figure out what it might be. I've tried
>
>' as string', ' as Unicode text' and 'POSIX
>
>path of ' without success.
>
>
>
>Using OS 10.3.3/10.3.4.
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.