on mouse up theObject event theEvent
set tempartwork to ("" & (path to application "AtomTunes") & "Contents:Resources:" & "thing.pict") as file specification
set tempartwork1 to ("Macintosh HD:" & (path to application "AtomTunes") & "Contents:Resources:" & "thing.pict" as string)
try
set theposixpath to (POSIX path of tempartwork1)
do shell script "rm " & theposixpath
end try
tell application "iTunes"
set trackthing to current track
set theArt to data of artwork 1 of trackthing
end tell
set file_reference to (open for access tempartwork with write permission)
try
set eof file_reference to 512
write theArt to file_reference starting at 513
close access file_reference
on error err
close access file_reference
error err
end try
set image of image view "update" of window "artworkWindow" to load image "Update"
set image of image view "artworkP" of window "artworkWindow" to load image "thing"
end mouse up
set tempartwork1 to ("Macintosh HD:" & (path to application "AtomTunes") & "Contents:Resources:" & "thing.pict" as string)
should perhaps just be
set tempartwork1 to (path to application "AtomTunes" & "Contents:Resources:" & "thing.pict") as string
(since path to application “Atom Tunes” should return the full path, starting with the volume name; I think your code is probably returning “Macintosh HD:Macintosh HD:Applications:AtomTunes.app:Contents:Resources:thing.pict”).
the path doesn’t seem to be the problem. When i first click the button that tells the artwork to load it does, but when i press it again, it should load a new picture. But it doesn’t.
I don’ know a lot about AppleScript Studio, but I don’t think the app knows that you’re writing a file to the Resources folder at run time. I think they need to be entered at compile time.
The other way to show an image in the image view is to use its posix path. For instance, I made a simple Studio app with an image view. The following script is run when the app starts. It creates the PICT file in the current user’s folder and loads it into the image view using the posix path. Remember that you should delete the image when loading new images into the image view.
on awake from nib theObject
set cur_user to (path to “cusr”) as string
tell application “iTunes”
set s to item 1 of (selection)
set a to first artwork of s
set d to data of a
end tell
set file_spec to (cur_user & “iTunesArt1.pict”) as file specification
set ref_num to (open for access file_spec with write permission)
try
set eof ref_num to 512
write d to ref_num starting at 513
close access ref_num
on error
close access ref_num
beep 2
end try
tell application “Finder”
set file type of file_spec to “PICT”
set creator type of file_spec to “???”
end tell
set file_path to (file_spec as string)
set posix_path to (POSIX path of file_path)
set image of theObject to load image posix_path
end awake from nib
If you allow the user to save the file in your app, then you should convert the PICT to some other file type because this picture is still not perfect I think.
well it still isn’t working for some reason, thxs for all your support! this has really helped me learn alot about the inner workings of applescript. If there is place where i can read more about terms such as, “eof” and “POSIX” please point me in the direction of it.
for now though, i have the following:
this is my on click the button update scripts:
on updateA()
set tempartwork to ("" & (path to me) & "Contents:Resources:" & "thing.pict") as file specification
set tempartwork1 to ("Macintosh HD:" & (path to me) & "Contents:Resources:" & "thing.pict" as string)
try
set theposixpath to (POSIX path of tempartwork1)
do shell script "rm " & theposixpath
end try
tell application "iTunes"
set trackthing to current track
set theArt to data of artwork 1 of trackthing
end tell
set file_reference to (open for access tempartwork with write permission)
try
set eof file_reference to 512
write theArt to file_reference starting at 513
close access file_reference
on error err
close access file_reference
error err
end try
set image of image view "artworkP" of window "artworkWindow" to load image "thing"
end updateA
on mouse up theObject event theEvent
updateA()
set image of image view "update" of window "artworkWindow" to load image "Update"
end mouse up
this is my on awake from nib script:
on artwork()
tell application "iTunes"
set trackthing to current track
set theArt to data of artwork 1 of trackthing
end tell
set tempartwork to ("" & (path to me) & "Contents:Resources:" & "thing.pict") as file specification
set file_reference to (open for access tempartwork with write permission)
try
set eof file_reference to 512
write theArt to file_reference starting at 513
close access file_reference
on error err
close access file_reference
error err
end try
set tempartwork1 to (tempartwork as string)
set theposixpath to (POSIX path of tempartwork1)
set image of image view "artworkP" of window "artworkWindow" to load image theposixpath
end artwork
on awake from nib theObject
artwork()
end awake from nib