probably this has been already discussed but I cannot find it.
Using Script Editor I can get the correct string when for example I execute the following script:
tell application "Adobe Photoshop CS5"
set colorSpace to (mode of current document) as string
end tell
When I run into Asoc Project (Xcode 5.0.1) I get «constant…»
I need to use something with If.else:
tell application "Adobe Photoshop CS5"
set colorSpace to (mode of current document)
if colorSpace is RGB then
set colorSpaceString to "RGB"
else
.
end if
end tell
The question is: there is a way to get correct coercion inside Xcode?
Your second sample is the correct way to do it. The first method works in a script editor, because it has the application’s terminology loaded and can coerce it. But when you put it in an application it will fail, because applications don’t load the terminology just to run.
For some properties I had to follow like you suggested:
tell application "Adobe Photoshop CS5"
-- Esamina lo spazio colore {bitmap, grayscale, duotone, indexed color, RGB, CMYK, Lab, multichannel}
set metodoColoreTmp to (mode of current document)
if metodoColoreTmp is bitmap then
set metodoColore to "bitmap"
else if metodoColoreTmp is grayscale then
set metodoColore to "grayscale"
else if metodoColoreTmp is duotone then
set metodoColore to "duotone"
else if metodoColoreTmp is indexed color then
set metodoColore to "indexed color"
else if metodoColoreTmp is RGB then
set metodoColore to "RGB"
else if metodoColoreTmp is CMYK then
set metodoColore to "CMYK"
else if metodoColoreTmp is Lab then
set metodoColore to "Lab"
else if metodoColoreTmp is multichannel then
set metodoColore to "multichannel"
end if
-- Bit Immagine 8/16/32 {one, eight, sixteen, thirty two}
set bitColoreTmp to (bits per channel of current document)
if bitColoreTmp is one then
set bitColore to 1
else if bitColoreTmp is eight then
set bitColore to 8
else if bitColoreTmp is sixteen then
set bitColore to 16
else if bitColoreTmp is thirty two then
set bitColore to 32
end if
end tell
Some others properties are coerced correctly. Example:
set nomeProfilo to (color profile name of current document) as string
In this case what I don’t understand is why this is coerced correctly while some other no.
If for any reason the profileName should not coerced should be a pain because of large amount of possibilities.
In my case I need to get this info to store on a DB and pass the to some handlers for image normalization.
For kel: when you try to coerce inside Xcode you get «constant ****Eigt» for bits of images and «constant ****082» for one of the color spaces. In Script Editor all works as expected like Shane explained.
That will probably work. It just depends whether you want your script loading all that terminology every time it’s run. You’re just increasing launch time and using more memory. In the scheme of things it’s probably not much, but it’s also one more thing that can go wrong. Is doing it the other way such a big deal, apart from the extra typing?