I created an Applescript XCode app. I have tried image well and image view. I get an exception thrown trying to connect the image view in IB The image well connects fine, but I cannot get theimage to update.
how can I get an image to display and swap in my app? all I find are references to Applescript Studio, which seems useless when I am using 10.6 SDK.
None of the functions work
fir instance
set imageURL to "file:///Users/roberthuttinger/Desktop/pic-022.jpg"
call method "loadImageInImageView:fromURL: of class "ImageLoader" with parameters {theImageWell, imageURL}
fails with error that xcode doesnt know what to do with ‘call method’ (and they are set up in .h and .m files)
How can simply display and swap an image in my applescript xcode app?!?
cheers,
bo
“call method” is only for AppleScript Studio. Assuming theImageWell is a property connected to the image view in IB, you want:
set imagePath to "/Users/roberthuttinger/Desktop/pic-022.jpg"
tell theImageWell to setImage_(imagePath)
after 14 hours I thank you for your reply. I thought it would be that easy, but… it doesnt work.
I have an image well
in my window in IB. it is linked with property theImageWell : missing value
in xcode.
the code I have for getting my image is:
tell application "iTunes"
set myTrack to (current track)
set n to name of myTrack
set arts to artworks of myTrack
if arts = {} then
--do nothing
else
set arts to item 1 of arts -- a track can contain multiple artwork; we choose the first one
set imageData to data of arts
my writeImageFile(imageData)
end if
set imagePath to "/Users/roberthuttinger/Desktop/00000.pict"
tell theImageWell to setImage_(imagePath)
end tell
on writeImageFile(imageData)
tell application "Finder"
set fileName to ("00000" & ".pict") as string
set myFile to (make new file at desktop with properties {name:fileName}) as alias
open for access myFile with write permission
set eof myFile to 512
write imageData to myFile as picture starting at 513
close access myFile
end tell
end writeImageFile
What is missing. Assuming it is linked correctly, shouldnt this work?
I am open to anything here.
thanks again!
cheers,
bo
Model: mini
Browser: Safari
Operating System: Mac OS X (10.6)
The first thing I’d try would be another pic – I have a vague recollection that PICTs no longer work in 64-bit apps; they’re certainly deprecated.
baby steppin…
try
set omgArtwork to data of artwork 1 of (current track)
tell theImageWell to setImage_(omgArtwork)
on error error_message
display dialog error_message
end try
results in this error:
NSImageCell's object value must be an NSImage
getting closer…
who knew copying itunes artwork to an image well would be this difficult
bo
set imagePath to "/Users/roberthuttinger/Desktop/skate_vsw_logo.gif"
tell theImageWell to setImage_(imagePath)
doesnt work. I can drag the image to the image well but I cannot get it to update in code
it should have been that simple… what can I be missing?
OK, I left out making an NSImage from the file. I think you’re going to have trouble with PICTs, and I think you’d be better off getting “raw data” rather than “data”. Even then, it seems like the data has to be saved to file, probably because AS’s data class isn’t what Cocoa expects.
Anyway, this works for me:
property imageView : missing value
on applicationWillFinishLaunching_(aNotification)
tell application "iTunes"
set myTrack to (current track)
set n to name of myTrack
set arts to artworks of myTrack
if arts = {} then
--do nothing
return
else
set arts to item 1 of arts -- a track can contain multiple artwork; we choose the first one
set imageData to raw data of arts
end if
end tell
-- write to temp file
set deskPath to path to temporary items as text
tell current application -- required for read/write commands
set fileRef to (open for access file (deskPath & "Test pic") with write permission)
set eof fileRef to 0
write imageData to fileRef
close access fileRef
end tell
tell current application's NSImage to set theImage to alloc()'s initWithContentsOfFile_(POSIX path of (deskPath & "Test pic"))
tell imageView to setImage_(theImage)
end applicationWillFinishLaunching_
wow thanks! thats was it!
a few pitfalls I didnt know about there:
tell current application
and a few other minor things…
thanks much!!! ill post the project when Im done.
cheers!
BTW, add http://scriptbuilders.net/files/shanesasobjcutilities0.9.html to your project and you can cut out the whole write-to-file business and move the data directly.