This part of my Applescript is a problem. Is it a bug, or am I doing something wrong?
******************
set a to 10
set filer to "/Users/dracon/Documents/Misc Graphics/Scanned Cover Art1/Suzuki Templates/" & "Suzuki " & a & ".jpg"
display dialog filer
tell application "Pixelmator Pro"
export the front document to file filer as JPEG with properties {compression factor:85}
end tell
***********************
I get the following error message:
error "Pixelmator Pro got an error: You can’t save the file “91EEE860-907B-46B3-B209-6071CDF13D67” because the volume “MacHDCAT” is read only." number -100
The display dialog in the script displays a perfectly formatted filepath and MacHDCAT is my hard drive and I can manually export the document from Pixelmator Pro
Applescript exporting document problem
2021-03-31 15:17:54
Hey there, I think the problem you're having is the path you're passing to the export command is in the POSIX format, while a file object (which is what the export command requires) can only be constructed from strings in the HFS style, i.e. "MacHDCAT:Users:dracon:Documents:Misc Graphics:Scanned Cover Art1:Suzuki Templates:Suzuki10.jpg". I'm basing this on the information here. Anyway, there are a couple of fixes for this. You can coerce the string to a POSIX file object like this:
P.S. You can wrap your code in applescript tags (surrounded by [ and ]) when sharing it on the forum to have the code nicely formatted.
set a to 10
set filer to "/Users/dracon/Documents/Misc Graphics/Scanned Cover Art1/Suzuki Templates/" & "Suzuki " & a & ".jpg"
display dialog filer
tell application "Pixelmator Pro"
export the front document to file (filer as POSIX file) as JPEG with properties {compression factor:85}
end tell
Or using HFS style notation should also work:
set a to 10
set filer to "MacHDCAT:Users:dracon:Documents:Misc Graphics:Scanned Cover Art1:Suzuki Templates:" & "Suzuki " & a & ".jpg"
display dialog filer
tell application "Pixelmator Pro"
export the front document to file filer as JPEG with properties {compression factor:85}
end tell
Hope that helps!P.S. You can wrap your code in applescript tags (surrounded by [ and ]) when sharing it on the forum to have the code nicely formatted.
2021-03-31 20:08:46
Thank you! That was it, and I used the second example which worked perfectly.
One of the difficulties was the error message - which was very misleading.
I have another question (probably simple) and rather than start a new post I wonder if you might shed some light....
One of the difficulties was the error message - which was very misleading.
I have another question (probably simple) and rather than start a new post I wonder if you might shed some light....
tell layer 1
tell the text content of myText
set its font to "ZapfChan Md BT"
set its size to 75
set its color to {65535, 0, 0}
end tell
end tell
I don't understand the color notation - except that the given example is pure red. Pixelmator seems to use RGB with the top value =255. Is there a simple way to convert the RGB as the color wheel in Pixelmator to this notation in Applescript? I couldn't find any reference to it on the web or in the Pixelmator Applescript dictionary.2021-04-01 08:54:52
AppleScript uses 16-bit-per-channel color codes. With 8 bits per channel (2^8), there are 256 tonal variations (from 0 to 255) and with 16 bits (2^16) there are 65536 (from 0 to 65535) tonal variations. Converting from 8-bit to 16-bit (which is then converted back to 8-bit) is relatively simple if you don't need total precision – you can simply multiply by 256. However, you will get lower values when the 8-bit color code is higher than 129 which is, I believe, down to rounding issues. Since 255*256 is 65,280 and this gets rounded down to 254, rather than up to 255. You can create a handler for this, though, that you can then easily reuse. That could look like this:
tell application "Pixelmator Pro"
tell the front document
tell the styles of layer 1
set its fill color to my convertTo16Bit(255, 255, 255)
end tell
end tell
end tell
on convertTo16Bit(RGB)
set outputColors to {}
repeat with inputColor in RGB
if inputColor ≥ 127 then
copy ((inputColor + 1) * 256) - 1 to end of outputColors
else
copy inputColor * 256 to end of outputColors
end if
end repeat
return outputColors
end convertTo16Bit