GC AppleScript to Double Canvas Size

The right place to speak and share about your experiences of GraphicConverter
Post Reply
User avatar
nello
Posts: 4
Joined: Fri Jun 24, 2022 3:40 pm
Country: United States of America

GC AppleScript to Double Canvas Size

Post by nello »

I’d like to create an AppleScript for Graphic Converter that is an applet; when I drop a file on it, Graphic Converter creates a new file in the same folder as the applet that doubles the size of the image’s canvas using white for the added canvas.

My questions are:
  • Where should I post questions about AppleScript?
  • Are there any example scripts to get me started?
Thank you. (Apologies for not posting on the right board.)
User avatar
forum_adm
Site Admin
Posts: 1814
Joined: Fri Dec 23, 2016 9:41 am
Location: Germany
Country: Germany
Contact:

Re: GC AppleScript to Double Canvas Size

Post by forum_adm »

Here is short script for opening and adding the margins:

tell application "GraphicConverter 11"

open "/Users/sampleuser/Desktop/2018-07-02 13.25.04.jpg"

set w to window 1

tell w
set dim to image dimension as list
end tell

set width to first item of dim as integer
set height to last item of dim as integer

tell w
change margins with {width / 2, height / 2, width / 2, height / 2}
end tell

-- close w

end tell
User avatar
nello
Posts: 4
Joined: Fri Jun 24, 2022 3:40 pm
Country: United States of America

Re: GC AppleScript to Double Canvas Size

Post by nello »

Thank you very much for getting me started on my script. I modified it somewhat to use a droplet instead of hardcoding a specific file:

Code: Select all

on open theOriginalImageFile
	--
	-- Configuration settings
	set blnSaveCopy to true #Save as copy; do not change original file.
	set strFileFormat to "PNG" #Convert and save image to .png file.
	tell application "GraphicConverter 11"
		open theOriginalImageFile
		set theWindow to window 1
		tell theWindow
			set listImageDimensions to image dimension as list
			set intWidth to first item of listImageDimensions as integer
			set intHeight to last item of listImageDimensions as integer
			change margins with {intWidth / 2, intHeight / 2, intWidth / 2, intHeight / 2}
		end tell
		set theResult to save theWindow as strFileFormat makeCopy blnSaveCopy
		close theWindow
	end tell
end open
Unfortunately, this line

Code: Select all

set theResult to save theWindow as strFileFormat makeCopy blnSaveCopy
throws this error:

Code: Select all

GraphicConverter 11 got an error: Can’t make "PNG" into type constant.
Why isn’t it allowing me to convert and save the image as a `.png` file?
User avatar
forum_adm
Site Admin
Posts: 1814
Joined: Fri Dec 23, 2016 9:41 am
Location: Germany
Country: Germany
Contact:

Re: GC AppleScript to Double Canvas Size

Post by forum_adm »

1. the path is missing in the save command
2. the format is an AppleScript constant

set theResult to save theWindow in filePathWithChangedExtension as PNG makeCopy blnSaveCopy
User avatar
nello
Posts: 4
Joined: Fri Jun 24, 2022 3:40 pm
Country: United States of America

Re: GC AppleScript to Double Canvas Size

Post by nello »

I want to enhance my droplet script to trap files that a user (accidentally) drops on it which Graphic Converter can NOT open.

I found an extensive list of file formats that Graphic Converter can import but I don’t know how to test a file to see whether it corresponds to one of these formats. I’m thinking that I need to check the file’s extension against a list of supported extensions.

Do you have a list of all the file extensions for all the file formats that Graphic Converter can open?

Alternatively, is there another way of trapping files that Graphic Converter can NOT open?

Thank you for your help.
User avatar
nello
Posts: 4
Joined: Fri Jun 24, 2022 3:40 pm
Country: United States of America

Re: GC AppleScript to Double Canvas Size

Post by nello »

forum_adm wrote: Mon Jun 27, 2022 7:47 am the format is an AppleScript constant
Is there a way to use a variable to specify this constant? Or, do I have to hard code a literal string?

Thank you for your help.
User avatar
forum_adm
Site Admin
Posts: 1814
Joined: Fri Dec 23, 2016 9:41 am
Location: Germany
Country: Germany
Contact:

Re: GC AppleScript to Double Canvas Size

Post by forum_adm »

The open command returns normally an error for unknown file formats.

Did you try to encapsulate the open command into a try block?
Post Reply