TweetFollow Us on Twitter

Introduction to Scripting GraphicConverter

Volume Number: 22 (2006)
Issue Number: 9
Column Tag: AppleScript Essentials

Introduction to Scripting GraphicConverter

by Benjamin S. Waldie

In last month's column, we began discussing scriptable creative applications. Specifically, we looked at Adobe Photoshop, and explored how opening, manipulating, and saving graphic files can be automated using AppleScript.

This month, we will discuss scripting GraphicConverter, another popular graphic conversion and manipulation application, which is available from Lemke Software GmbH. While not packed with all the bells and whistles of something like Adobe Photoshop, GraphicConverter does offer quite a lot of bang for your buck.

GraphicConverter supports opening approximately 190 different graphic file formats, and saving approximately 79 different graphic file formats. One of GraphicConverter's great fortes is converting graphics from one type to another, hence its name. It also possesses the ability to manipulate graphics by rotating them, scaling them; applying filters, and more, many of the types of tasks that users often want to automate in order to batch process their graphic files. Furthermore, many features of GraphicConverter are controllable via AppleScript.

If you are not yet familiar with GraphicConverter, or if you plan to follow along with the examples in this month's column, then I encourage you to download the fully functional demonstration version of GraphicConverter from the Lemke Software website at <http://www.lemkesoft.com/>. For the cost of the non-demo version (currently only $30 for a single user license!), you may find it well worth adding to your software collection, especially if you plan to automate graphic conversion and manipulation with AppleScript, but don't need all of the functionality of something like Photoshop.

Lemke Software updates GraphicConverter on a very regular basis, and many of these updates include changes to its AppleScript terminology, which may require that you make changes to existing scripts. In any case, to ensure the highest level of AppleScript support, it is best to ensure that you are using the latest version of GraphicConverter. Just be sure to review the release notes in order to determine which AppleScript changes, if any, have been made between versions. Also, in case an updated version of GraphicConverter introduces AppleScript changes before this month's column is published, please note that all code that follows was written and tested with GraphicConverter version 5.9.1.

Getting Started

Opening Graphics

Whether you plan to automate GraphicConverter for the purpose of converting graphic files from one type to another or for manipulating graphics, you will most likely need to open them first. The reason I say most likely is because there are actually ways to batch process and interact with graphic files using GraphicConverter and AppleScript without writing code to open them. I would encourage you to explore GraphicConverter's AppleScript dictionary carefully to learn more about these and many other scriptable functions that we won't have a chance to touch on in this month's column.

There are a few different ways that graphics can be opened in GraphicConverter via AppleScript. Like most applications, GraphicConverter has an open command, which may be used to open graphic files. The following example code demonstrates the usage of this command.

set theImage to choose file with prompt "Please select an image file:"
tell application "GraphicConverter"
   open theImage
end tell

Although the open command will usually suffice, you may actually want to consider using the silentopen command instead. At times, opening certain graphic files may cause a dialog or error message to be displayed, and the silentopen command will attempt to open a specified graphic file without displaying such a dialog.

While this command may not prevent all dialogs from being displayed, it can certainly help to reduce the possibility of one appearing and holding up your automated process.

tell application "GraphicConverter"
   silentopen theImage
end tell

    TIP: When using the silentopen command, if you still encounter a dialog when opening a certain type of file, be sure to select the Don't show this note again... checkbox in the dialog, in order to prevent that specific dialog from appearing again in the future.

GraphicConverter also has the ability to download and open an image using a URL, rather than referencing a local file. This is done using the urlopen command. For example:

tell application "GraphicConverter"
   urlopen "http://www.mactech.com/images/mt_logo_209x043.gif"
end tell

Working with Graphics



Figure 1. A Graphic Window in GraphicConverter

Referencing Graphics

When AppleScripting GraphicConverter, there is not an actual graphic class. Rather, a graphic is referenced using the window class. The following code will retrieve a reference to the frontmost graphic window.

tell application "GraphicConverter"
   front window
end tell
--> window "mt_logo_209x043.gif (Indexed)" of application "GraphicConverter"

You will notice that, in the result of the above code, the window's name contains the suffix (Indexed), following the graphic file's name. GraphicConverter has added this automatically to the window's (not the file's) name, in order to indicate that the mode of the graphic is set to Indexed Color.

As you might expect, based on the previous example's result, graphic windows can also be referenced by name. For example:

tell application "GraphicConverter"
   tell window "mt_logo_209x043.gif (Indexed)"
      -- Do something
   end tell
end tell

Again, the name of the graphic file referenced in the previous example does not actually contain the suffix (Indexed). Because of this, GraphicConverter is flexible, and you can optionally choose to refer to the graphic window using its referenced file's name, without the mode suffix. For example:

tell application "GraphicConverter"
   tell window "mt_logo_209x043.gif"
      -- Do something
   end tell
end tell

When referring to graphic windows by name, please be aware that the window name may change when performing various functions, such as changing the mode of the graphic, or saving the graphic using a new file name or type. Because of this, you may want to consider referring to graphic windows by their index, or front to back positioning. Of course, be aware that this may change as well, if new graphics are opened, or the windows are reordered. For example:

tell application "GraphicConverter"
   tell window 1
      -- Do something
   end tell
end tell

Throughout this month's column, I will be referring to graphic windows by index.

Working with Graphic Properties

In GraphicConverter, graphic windows possess a number of AppleScript-accessible properties, some of which are modifiable and some of which are read only. We will be discussing a few of these properties below. To view a complete list of accessible properties, please refer to the window class, located in the Standard Suite in GraphicConverter's AppleScript dictionary. See figure 2.



Figure 2. GraphicConverter Window Properties

Assuming that a graphic window corresponds to a saved graphic file, and is not a new unsaved window, you may retrieve a reference to that file by accessing the file property of the window. For example:

tell application "GraphicConverter"
   file of window 1
end tell
--> file "Macintosh HD:Users:bwaldie:Desktop:mt_logo_209x043.gif"

Another accessible property of a graphic window is resolution. This property's value will be a list, indicating the horizontal and vertical resolution of the graphic. For example:

tell application "GraphicConverter"
   resolution of window 1
end tell
--> {72, 72}

The resolution property is also modifiable, and may be adjusted, if desired. The following code will change the horizontal and vertical resolution of the frontmost graphic window to 150 dpi.

tell application "GraphicConverter"
   set resolution of window 1 to {150, 150}
end tell

In GraphicConverter, the resolution of a graphic may also be modified using the change resolution command, which can be found in the GraphicConverter Suite in GraphicConverter's AppleScript dictionary.

tell application "GraphicConverter"
   change resolution of window 1 to {150, 150} with resample
end tell

Unlike the resolution property of a graphic window, the change resolution command provides the ability to specify whether the image should be resampled to the new resolution.

Another modifiable property of a graphic window is mode. The value of this property will be an integer that specifies the mode of the graphic - 0 for bitmap, 1 for indexed color, 2 for grayscale, 3 for RGB, and 4 for CMYK. For example, the following code would change the mode of the frontmost graphic to CMYK.

tell application "GraphicConverter"
   set mode of window 1 to 4
end tell

Accessing File Info

As you may know, or recall from last month's column, it is possible to associate metadata, such as captions, keywords, and more, with certain types of graphics. In GraphicConverter, many of these metadata fields are accessible to AppleScript via properties of a graphic window.

The following code, for example, will retrieve the caption of the frontmost graphic window by accessing the window's IPTC caption property. If a caption is not applied to the graphic, then an empty string will be returned.

tell application "GraphicConverter"
   IPTC caption of window 1
end tell
--> "Trip to the beach."

To retrieve a list of keywords applied to a graphic, access the graphic window's IPTC keywords property.

tell application "GraphicConverter"
   IPTC keywords of window 1
end tell
--> {"Summer", "Vacation"}

GraphicConverter provides AppleScript with access to numerous IPTC metadata properties, which, in addition to being readable, may be modified if desired. The following code demonstrates how new keywords could be appended to the existing keywords of a graphic window.

tell application "GraphicConverter"
   tell window 1
      set theExistingKeywords to IPTC keywords
      set IPTC keywords to (theExistingKeywords & {"Beach", "Fun"})
      IPTC keywords
   end tell
end tell
--> {"Summer", "Vacation","Beach", "Fun"}

Another way to access and modify a graphic's metadata is by using the get file iptc and set file iptc commands, both of which can be found in the GraphicConverter Suite of GraphicConverter's AppleScript dictionary. However, unlike the previous examples, these commands will allow the metadata of the graphic file to be accessed directly, without actually opening the graphic.

The following example code demonstrates the usage of the get file iptc command. Note that this command will return a list of all IPTC metadata fields at once. If you plan to use this command, then you will need to determine which metadata field each list item corresponds to.

set theGraphicFile to choose file with prompt "Select a graphic file:"
tell application "GraphicConverter"
   get file iptc theGraphicFile
end tell
--> {"Trip to the beach.", "", "", "", "Ben Waldie", "", "", "", "Beach Fun", "", "", "", "", 
   "", "", "", "-1", "Summer,Vacation,Beach,Fun", "Copyright Automated Workflows, LLC", 
   "http://www.automatedworkflows.com"}

As the next example demonstrates, the set file iptc command requires that a list of metadata field values be provided following the to labeled parameter. Like the previous example, to properly utilize this command, you will need to determine which metadata field each list item corresponds to.

set theGraphicFile to choose file with prompt "Select a graphic file:"
tell application "GraphicConverter"
   set file iptc theGraphicFile to {"2006 Summer trip to the beach.", "", "", "", "Ben Waldie", 
   "", "", "", "Beach Time Fun", "", "", "", "", "", "", "", "-1", "Summer,Vacation,Beach,Fun", 
   "Copyright 2006 Automated Workflows, LLC", "http://www.automatedworkflows.com"}
end tell

Another command, get file exif, may be used to retrieve the EXIF (Exchangeable Image File Format) data of a graphic file, again, in list format.

Manipulating Graphics

As mentioned, GraphicConverter can also be used to perform certain types of image manipulations. Not all of these are presently AppleScriptable, but a number of them are, and we will discuss a handful of these now.

Rotating Graphics

In order to rotate a graphic window, use the rotate command, and specify the desired angle of rotation. For example, the following code would rotate a graphic 90 degrees counter-clockwise.

tell application "GraphicConverter"
   rotate window 1 to angle 90
end tell

To rotate clockwise, specify a negative numeric value for the angle parameter. The rotate command also has some optional properties, which you can find in GraphicConverter's AppleScript dictionary.

Mirroring Graphics

The mirror command may be used to mirror a graphic window either horizontally or vertically. The following code demonstrates the proper usage of this command.

tell application "GraphicConverter"
   mirror window 1 in horizontal
end tell

Unsharp Mask

In GraphicConverter, it is possible to manually apply numerous filters to graphic windows. Some of these, such as unsharp mask, are accessible via AppleScript. To apply the unsharp mask filter, use the unsharp mask command, and specify the desired values for the command's radius, amount, and threshold parameters. For example:

tell application "GraphicConverter"
   unsharp mask window 1 radius 100 amount 100 threshold 0
end tell

Changing Brightness

Many visual aspects of graphic windows, including the gamma, hue, brightness, contrast, and more, are modifiable using commands in the GraphicConverter Suite. This next example shows how to change the brightness of a graphic window to a specified value.

tell application "GraphicConverter"
   change brightness window 1 to -25
end tell

Outputting Graphics

The save command is used to save a graphic window. At its most basic level, this command requires a single parameter - a reference to the window to be saved. To save a window in this manner, the window must reference an existing file in the Finder.

tell application "GraphicConverter"
   save window 1
end tell

To save a newly created graphic window, which does not yet reference a file in the Finder, you will need to specify the format, as well as the output path for the saved file. This is done by using the save command's in and as parameters. These parameters may also be used when you want to save a graphic window that does reference an existing file into a new location, or in a different format.

GraphicConverter can save approximately 79 different formats of graphic files. For a complete list of available save types, consult the save command in the Standard Suite of GraphicConverter's AppleScript dictionary. The following example code demonstrates how to save a graphic window as a JPEG to a file named Converted Graphic.jpg on the desktop. Please note that this would overwrite an existing file with the same name, if present.

set theOutputPath to (path to desktop folder as string) & "Converted Graphic.jpg"
tell application "GraphicConverter"
   save window 1 in theOutputPath as JPEG
end tell

When manually saving graphics in GraphicConverter, you will find that certain formats, such as JPEG and TIFF, have modifiable options, which can affect the saved file's quality, file size, and more. While not all of these options may be specified using AppleScript, some can. Unlike the manual process, however, with AppleScript, these options are not specified during the save process. Rather, they are specified via properties of the graphic window.

JPEG is one format with certain options that are modifiable via AppleScript, such as quality and compression type. The following code demonstrates how to adjust some of these options and then save the frontmost graphic window in JPEG format to the desktop.

set theOutputPath to (path to desktop folder as string) & "Converted Graphic.jpg"
tell application "GraphicConverter"
   tell window 1
      set JPEG quality to 30
      set JPEG progressive to true
      save in theOutputPath as JPEG
   end tell
end tell

Resources for Continued Learning

If you are interested in learning more about scripting GraphicConverter, then I would encourage you to visit the GraphicConverter AppleScripts webpage on the Lemke Software website at <http://www.lemkesoft.com/en/graphscripts.htm>. Here, you will find a number of downloadable AppleScripts, which you may use or edit to meet the needs of your specific workflow. You can also search MacScripter.net's ScriptBuilders section at <http://scriptbuilders.net/> for GraphicConverter scripts.

In Closing

As you can see from the examples in this month's column, AppleScript can be used to automate a number of image manipulation and conversion processes using GraphicConverter. Yet, we have only really scratched the surface. Be sure to explore GraphicConverter's AppleScript dictionary more fully in order to learn more about its incredibly useful scriptable capabilities. Also, don't forget that new AppleScript features are introduced to this application on a fairly regular basis, so check the Lemke Software website frequently for updated versions.

Until next time, keep scripting!


Ben Waldie is the author of the best selling books "AppleScripting the Finder" and the "Mac OS X Technology Guide to Automator", available from <http://www.spiderworks.com>, as well as an AppleScript Training CD, available from <http://www.vtc.com>. Ben is also president of Automated Workflows, LLC, a company specializing in AppleScript and workflow automation consulting. For years, Ben has developed professional AppleScript-based solutions for businesses including Adobe, Apple, NASA, PC World, and TV Guide. For more information about Ben, please visit <http://www.automatedworkflows.com>, or email Ben at <ben@automatedworkflows.com>.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

iMazing 2.17.16 - Complete iOS device ma...
iMazing is the world’s favourite iOS device manager for Mac and PC. Millions of users every year leverage its powerful capabilities to make the most of their personal or business iPhone and iPad.... Read more
VueScan 9.8.22 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
MacPilot 15.0.2 - $15.96 (53% off)
MacPilot gives you the power of UNIX and the simplicity of Macintosh, which means a phenomenal amount of untapped power in your hands! Use MacPilot to unlock over 1,200 features, and access them all... Read more
Visual Studio Code 1.85.0 - Cross-platfo...
Visual Studio Code provides developers with a new choice of developer tool that combines the simplicity and streamlined experience of a code editor with the best of what developers need for their... Read more
Spotify 1.2.26.1187 - Stream music, crea...
Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue puts... Read more
Transmission 4.0.5 - Popular BitTorrent...
Transmission is a fast, easy, and free multi-platform BitTorrent client. Transmission sets initial preferences so things "just work", while advanced features like watch directories, bad peer blocking... Read more
Fantastical 3.8.9 - Create calendar even...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event details... Read more
Notion 3.0.0 - A unified workspace for m...
Notion is the unified workspace for modern teams. Features: Integration with Slack Documents Wikis Tasks Release notes were unavailable when this listing was updated. Download Now]]> Read more
GarageBand 10.4.10 - Complete recording...
GarageBand is the easiest way to create a great-sounding song on your Mac. Add realistic, impeccably produced and performed drum grooves to your song with Drummer. Easily shape the sound of any... Read more
Pacifist 4.1.0 - Install individual file...
Pacifist opens up .pkg installer packages, .dmg disk images, .zip, .tar. tar.gz, .tar.bz2, .pax, and .xar archives and more, and lets you extract or install individual files out of them. This is... Read more

Latest Forum Discussions

See All

Best iPhone Game Updates: ‘Bloons TD 6’,...
Hello everyone, and welcome to the week! It’s time once again for our look back at the noteworthy updates of the last seven days. We’re getting well into the month now, which means we’ll be seeing more holiday-themed updates this time. Only a couple... | Read more »
‘DOOM’ 30th Anniversary Stream Featuring...
id Software’s DOOM ($4.99) celebrated its 30th anniversary over the weekend. While I didn’t play it literally when it launched, I adored the shareware version I played hundreds of times until I finally got the full game. | Read more »
‘Shadowverse: Worlds Beyond’ Is a New Fr...
At its Shadowverse Next 2024 event, Cygames announced Shadowverse: Worlds Beyond for iOS, Android, and PC. This new game will have many new features including a lobby system that allows you to play Mahjong, go fishing, and more. If you ever wanted... | Read more »
Fontaine frolics in a festival with the...
Fontaine has finally overcome a fairly turbulent time and it's time to get back to the important things in Genshin Impact. Version 4.3, Roses and Muskets, will kick off December 20th and bring Travelers to one of the nation's most important events... | Read more »
TouchArcade Game of the Week: ‘Sonic Dre...
I can still remember the time I played my first 3D Sonic game. It was at Hollywood Video (that’s a video rental store for you young ones out there) and my buddy was the manager, and he invited me and my friend to hang out in the store after they... | Read more »
SwitchArcade Round-Up: Strictly Limited...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for December 8th, 2023. In today’s article, we start off with a couple of news items. Nothing from The Game Awards, that’s a bit beyond the scope of what I usually do here. But I do have... | Read more »
Football Manager 2024 Interview – We Tal...
Last month, SEGA and Sports Interactive released Football Manager 2024 on Apple Arcade (Touch), Netflix (Mobile), consoles, PC, and even Game Pass. If you missed my detailed review covering many versions of the game, read it here. | Read more »
‘Shiren the Wanderer: The Mystery Dungeo...
Recently, my son and I were invited to attend a special hands-on preview event at Spike Chunsoft’s headquarters in Tokyo to play the upcoming Shiren the Wanderer: The Mystery Dungeon of Serpentcoil Island for Nintendo Switch, which is scheduled for... | Read more »
Apple Arcade Weekly Round-Up: Updates fo...
We just had a huge content drop on Apple Arcade earlier this week with Sonic Dream Team, Disney Dreamlight Valley, Puzzles and Dragons, and more hitting the service. Today (and as of a few days ago), many notable games on the service have gotten... | Read more »
‘Genshin Impact’ Version 4.3 Update “Ros...
Following two trailers during The Game Awards 2023, HoYoverse has more news today with the next major Genshin Impact (Free) update detailed for all platforms. | Read more »

Price Scanner via MacPrices.net

13-inch M2 MacBook Airs are on Holiday sale f...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs in stock and back on Holiday sale for $150-$200 off MSRP in Space Gray, Silver, Starlight, and Midnight colors. Their prices are among the lowest... Read more
15-inch M2 MacBook Airs are back on Holiday s...
Apple retailers have 15-inch M2 MacBook Air back on Holiday sale for $250 off MSRP. Here is where to find the cheapest 15″ Air today: (1): Apple 15-inch MacBook Airs with M2 CPUs are in stock and on... Read more
Update: Apple Watch Series 9 models now $70 o...
Walmart has Apple Watch Series 9 models on Holiday sale for $70 off MSRP on their online store this weekend (that’s $20 cheaper than their earlier price). Sale prices available for online orders only... Read more
Apple’s AirTags 4-Pack is on Holiday sale for...
Apple retailers have 4-pack AirTags on sale this weekend for $19 off MSRP as part of their Holiday sales. These make a great stocking stuffer: (1): Amazon has Apple AirTags 4 Pack on sale for $79.99... Read more
Sunday Sale: $100 off every Apple iPad mini 6
Amazon is offering Apple’s 8.3″ iPad minis for $100 off MSRP, including free shipping, as part of their Holiday sale this weekend. Prices start at $399. Amazon’s prices are the lowest currently... Read more
16-inch M3 Pro MacBook Pros (18GB/512GB) are...
Looking for the best price on a 16″ M3 Pro MacBook Pro this Holiday shopping season? B&H and Amazon are currently offering a $250 discount on the 16″ M3 Pro MacBook Pro (18GB RAM/512GB SSD),... Read more
Apple Watch SE models on Holiday sale for $50...
Walmart has Apple Watch SE GPS-only models on Holiday sale on their online store for $50 off MSRP this weekend. Sale prices for online orders only, in-store prices may vary. Order online, and choose... Read more
Apple Watch Series 9 models on Holiday sale t...
Walmart has Apple Watch Series 9 models on Holiday sale for $50 off MSRP on their online store this weekend. Sale prices available for online orders only, in-store prices may vary. Order online, and... Read more
Apple has the 13-inch M2 MacBook Air in stock...
Apple has Certified Refurbished 13″ M2 MacBook Airs available starting at only $929 and ranging up to $210 off MSRP. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year... Read more
Apple’s 10th-generation iPads on Holiday sale...
Amazon has Apple’s 10th-generation WiFi iPads on sale for $100 off MSRP, starting at only $349, as part of their Holiday sales this weekend. With the discount, Amazon’s prices are the lowest we’ve... Read more

Jobs Board

Principal Offering Sales - Modern Workplace...
…Job Description **Who you are** + **Drives Modern Workplace sale, focusing on Apple Managed Services across the enterprise globally.** + **Owns the Apple Read more
Material Handler 1 - *Apple* (1st shift) -...
Material Handler 1 - Apple (1st shift)Apply now " Apply now + Start apply with LinkedIn + Apply Now Start + Please wait Date:Dec 8, 2023 Location: Irwindale, CA, US, Read more
Macintosh/ *Apple* Systems Administrator, TS...
…to a team-based environment. + Perform systems administration support tasks for Apple MacOS and iOS operating systems. + TDY travel (approximately 25%) for Read more
Principal Offering Sales - Modern Workplace...
…Job Description **Who you are** + **Drives Modern Workplace sale, focusing on Apple Managed Services across the enterprise globally.** + **Owns the Apple Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.