Newbe: Can't get GraphicConverter to save my image

I think Finder/GraphicConverter are having trouble with the path to save the converted image in.
This should work:

set new_item to (destFolder & "scaled." & (name of this_item)) as string
	tell application "GraphicConverter"
		open this_item
		scale window 1 vertical 0.5 horizontal 0.5
		save window 1 in new_item as JPEG with makeCopy
	end tell

Good scripting
Farid

That really got me going, however, only until I ran into the next barricade…
I know handle the creation of the path and filename in a seperate loop that calls upon my conversion routine. As is, this worked rather intermittendly. So, I went into a frenzy of trial and error and it turns out AppleScript is sending it’s instructions out oo fast. It doesn’t wait until GraphicConverter is done loading the picture and thus GC doesn’t ‘yet’ know what to do. So this:

-- convertWithGCX
-- 
-- Confert my_file to a jpeg named target_file using GraphicConverter
-- any known image type can be used, in theory...
on convertWithGCX(my_file, target_file)
	tell application "GraphicConverter"
		activate
		open {my_file} with name
	end tell
	
	-- Need to delay the script until it's ready loading the file...
	activate
	display dialog "Saving file as " & target_file
	
	tell application "GraphicConverter"
		activate
		-- got to get current window
		-- display dialog "Saving file as " & target_file
		save window 1 in target_file as JPEG with makeCopy without wwwready
		close window 1
	end tell
end convertWithGCX

Now, as long as I wait for GCX to finish loading my picture before I hit ok, everythings fine, but I want this to run unattended, so how do I make it wait and continue when it’s fiinshed loading the pic? (Possibly just continue after 5 or 10 seconds)

the command to let AS wait during code execution is

delay x
--where x is the number of seconds the script should pause

Hope it helps
Farid

Yes, that does seem to wrok quite well!! Grande, my first test finally went fully automated (only 2 files)
Now I only need to finish writing my copy actions and scale all the jpegs, but that all seems like childsplay and I have plenty of examples on the subject :slight_smile:
Thanks for the few hints!!

Inserting a delay should work well, as long as it’s large enough to allow for slower conditions, such as opening bigger files, etc. However, given a large enough safety margin, the script might then take longer than necessary to process files - by waiting needlessly for windows that have already opened.

Another way to approach this might be to introduce a checking repeat loop, perhaps with a very small delay, to allow the script to continue as soon as the required window appears.

It should also be possible to reduce the amount of work carried out within the main repeat, by completing part of the string concatenation before actually entering the loop.

Here’s an example of what I mean (tested using GC 5.5.2 X):

on open some_items
	set destFolder to ((choose folder with prompt ¬
		"Choose a destination folder:") as string) & "scaled."
	convertIt(destFolder, some_items)
end open

on convertIt(destFolder, some_items)
	repeat with this_item in some_items
		tell application "Finder" to set file_name to this_item's name
		tell application "GraphicConverter" to tell window file_name
			open this_item
			repeat until exists
			delay 0.2
			end repeat
			scale vertical 0.5 horizontal 0.5
			save in destFolder & file_name as JPEG with makeCopy
			close saving no
		end tell
	end repeat
end convertIt

That’s an excellent suggestion, I simply was nowhere near understanding how to check for existence. So I will definitely try and implement that part of your script. As towards the string conversion, it’s all well and fun within this limited context, but considdering the entire scope of what I’m attempting, mass-conversion (MRW to JPEG), storing by year/month/date, preservation of original images, scaling for webaccessability and thumbnailing, in the end it will require several string concatenations within the main-loop.
Again though, it is a verry good idea to make sure I do as many work ahead of time, requiring as little processing as possible while doing the conversion.

Thanx for the great post, I hope I can get it implemented today. And might be able to show the results then too.

Martin

My main point about concatenation (or any other operation) in repeat loops was really concerning the possibility of processing large batches. It probably matters little how a script progresses when only a few files are involved. However, in a loop that might iterate hundreds (or even thousands) of times, it becomes increasingly important to place all non-essential operations outside it. The cumulative effect of moving even the tiniest operation in this way could save a considerable amount of total processing time in the end.

As scripts become larger, more complex and more ambitious (as they inevitably do), such attention to detail really can pay substantial dividends. :slight_smile:

Good luck with the script!

Allas, I tried to incorporate your scripting example, but it won’t work. Even testing the unmodified posted script doesn’t work. Testing with ‘v5.6.1 X’ the error I get is ‘Some data was the wrong type’.
When incorporated into my larger script it returns with ‘GraphicConverter got an error: window “batch_conversion” doesn’t understand the exists message.’
When attempting to create a test-script that I can run from the editor (no drag-drop) I run into the same problem. the produced script is:

on run
	tell application "Finder"
		set my_file to (choose file with prompt "Pick your file")
		-- display dialog my_file as text
		set my_path to (choose folder with prompt "Pick you destination")
		-- display dialog my_path as text
	end tell
	convertIt((my_path as string) & "scaled.", {my_file})
end run

on open some_items
	set destFolder to ((choose folder with prompt ¬
		"Choose a destination folder:") as string) & "scaled."
	convertIt(destFolder, some_items)
end open

on convertIt(destFolder, some_items)
	repeat with this_item in some_items
		tell application "Finder" to set file_name to this_item's name
		set file_name to searchReplaceText(".mrw", ".jpg", file_name)
		tell application "GraphicConverter" to tell window file_name
			open this_item
			repeat until exists
				delay 0.2
			end repeat
			scale vertical 0.5 horizontal 0.5
			save in destFolder & file_name as JPEG with makeCopy
			close saving no
		end tell
	end repeat
end convertIt

(*
ripped from: http://bbs.applescript.net/viewtopic.php?id=11449
searchReplaceText(searchTerm, replaceTerm, theText)
Replaces a string found in a text by another string.
This handle supports lists of search/replace terms.

Parameters:
searchTerm: the text to search for
replaceTerm: the text to use as replacement
theText: the text to search/replace

Examples:
searchReplaceText("foo", "bar", "You are a foo") --> "You are a bar"
searchReplaceText({"foo", " a "}, {"bar", " one "}, "You are a foo") --> "You are one bar"
*)

to searchReplaceText(searchTerm, replaceTerm, theText)
	set searchTerm to searchTerm as list
	set replaceTerm to replaceTerm as list
	set theText to theText as text
	
	set oldTID to AppleScript's text item delimiters
	repeat with i from 1 to count searchTerm
		set AppleScript's text item delimiters to searchTerm's item i
		set theText to theText's text items
		set AppleScript's text item delimiters to replaceTerm's item i
		set theText to theText as text
	end repeat
	set AppleScript's text item delimiters to oldTID
	
	return theText
end searchReplaceText

Now I realise, it could be a problem with my GC versions, but I sure don’t hope so, I can’t go back to a previous version, it would defeat the purpose of my scripting, I need the latest version for it’s understanding of .mrw formats.

Any tips?

Martin

Bummer - but never mind… :wink:

[snip: some non-critical parts of script]

One of the potential problems introduced in your version is that the value of ‘file_name’ may be changed (by the ‘searchReplaceText’ handler) - before GC can check for a window with the original name.

However, from the error described, I don’t think that’s the problem here. (I’ve included a fix for it below, anyway).

It may be that my rather condensed syntax has confused your version of GC - in which case we could try separating the general GC statements from the more window-specific stuff, something like this:

on convertIt(destFolder, some_items)
	repeat with this_item in some_items
		tell application "Finder" to set file_name to this_item's name
		set new_name to switchExtension of file_name from ".mrw" to ".jpg"
		tell application "GraphicConverter"
			open this_item
			repeat until exists window file_name
				delay 0.2
			end repeat
			tell window file_name
				scale vertical 0.5 horizontal 0.5
				save in destFolder & new_name as JPEG with makeCopy
				close saving no
			end tell
		end tell
	end repeat
end convertIt

If that doesn’t work, then I’d hope that your version can at least count windows. :confused:

If so, we could try something like this instead:

on convertIt(destFolder, some_items)
	repeat with this_item in some_items
		tell application "Finder" to set file_name to this_item's name
		set file_name to switchExtension of file_name from ".mrw" to ".jpg"
		tell application "GraphicConverter"
			set windowCount to count windows
			open this_item
			repeat while (count windows) is windowCount
				delay 0.2
			end repeat
			tell window 1
				scale vertical 0.5 horizontal 0.5
				save in destFolder & file_name as JPEG with makeCopy
				close saving no
			end tell
		end tell
	end repeat
end convertIt

You’ll see that, in both of the above examples, I’ve suggested replacing the ‘searchReplaceText’ with one called ‘switchExtension’.

There’s nothing essentially wrong with the original handler…

Indeed, I happily use AppleScript’s text item delimiters in numerous text-mungeing situations. However, I wondered if the handler might just be a little ‘hefty’ for this particular job. My suggested replacement, which is considerably shorter (but should achieve exactly the same results), looks like this:

to switchExtension of nameString from searchExt to replaceExt
	tell nameString to if it ends with searchExt then ¬
		return text 1 thru -(1 + (count searchExt)) & replaceExt
	nameString
end switchExtension

No worries, Martin. I’m sure that, between us, we can come up with a solution that works with both versions. :slight_smile:

OK, Martin - I’ve now tested this using GC V5.6.1 X, and every version of the script works fine here (as it did with V5.5.2 X). That means it may be more to do with OS considerations (I’m testing in 10.2.8 - and I see you’re in Tiger).

GC doesn’t seem to like dealing with unicode text, although there aren’t that many instances of it in the script - since the alias-to-path coercions return strings. You might try coercing names supplied by Finder to strings - just in case the unicode text returned from there is causing a problem (although I think it unlikely):

tell application "Finder" to set file_name to this_item's name as string

If you’d like to pursue this further, I have a few questions:

¢ Can you identify exactly where in the script the ‘Some data was the wrong type’ error is occurring?
¢ Do you have any accented characters in your disk/folder/file names?
¢ Is FileVault activated on your system?

I could be barking up the wrong tree here, but it’s probably worth eliminating some of these possibilities.

Certainly sounds like it. That should teach me for being an early adopter :wink:

I agree with you but I’m at my dayjob at this point in time, I was just grabbing the page for further consideration on the way home in the bus. If I can get some testing done on the way home I’ll get you some details when I get back within an online environment.
However, do considder that I am a newbe to AppleScript, I wouldn’t know how to figure out where anything is happening without trial and error. I originally adepted your script to the on run version in stead of the on open handler because I’ve found that running the script from the editor returns to the line of code where an error has occured, but correct me if I’m wrong and do educate me if you know of a good debugger :slight_smile:

P.S. I’m not a programming newbe, just new to AppleScript as a boggling language when compared to the strict syntax of Java and similar.

On the save message, or so it seems.

Could verry well be, but I’m not sure what would count as an accented character, here’s an example name that will fail on my system:
Macintosh HD:Users:mreuring:Pictures:converted:2005:04:11:original:test.1_3_1.jpg

  1. Uhm, hmmm, how can I say this in a way that won’t make me feel completely incompetent? You see, I’ve been a troubleshooter/repairman/sysop right up until Mac OSX.1. Since then I’ve had a G3 as a toy sitting in my room, doing not much other than looking cool when my geek PC-friends came around and playing music on iTunes. Now I’ve recently, verry recently, aquired a brand new powerbook to work on the road and enhance my photography options, but, hmmm, I don’t know didly-you-know-what about all the tweaks and features of OS X :slight_smile:
  2. In short, what are you talking about?

So, my attempt at writing a cool AppleScript to convert/prep/file the images on my camera has, so far, been less-than-optimal.

I’ve tried incorporating all of your sugestions into my single to-be-conversion script. The results are still disapointing. I can’t get that delay loop to work at all. I have, however, had an encounter with the ‘wrong type’ error and succesfully fixed that using the ‘as string’ hack in apropriate places. But, neither the exists loop nor the count loop are willing to cooperate, using a delay 20 will work, it’s just far from desirable.

I’m beginning to notice a pattern in the behaviour though. Whenever I try to instantly continue commanding GCX it will return with a ‘window “blahblah” doesn’t understand your … message’, with a small difference in the count case where it returns with ‘every window doesn’t understand your count message’. The tricky part is, it won’t respond until I’ve clicked to the gcx window and back to the script file. And no, using activate to switch to foreground doesn’t help.
It’s starting to smell like GCX’s windows don’t understand any commands while still loading their contents. I will provide you with a link to an example .mrw file, in case you want to test with a 8Mb raw image, I for one wouldn’t mind hearing if it will work on your end…
http://www.windgazer.nl/images/test.1_3_1.MRW

Still testing on my end, but it’s getting hopeless, I will most likely stick with the delay 20 as it is and see if I can get the script to simply copy my jpg’s. When last I tested it also failed to perform a simple duplicate directive :frowning:

Thanx for your help so far!!
Martin

Hmm… :rolleyes:

Incidentally, you mentioned in an earlier message that you’ve been using a run handler to test your droplets. Often, that’s exactly what I do, and for precisely the same reason: you usually get to see exactly where an error is taking place. To save time, I sometimes comment out any choose file/folder dialogs, too - and insert temporary aliases instead.

Thanks for the info, Martin. I was thinking more of characters like “á”, "à ", “â”, “ä”, “ã”, “Ã¥”, “ó”, “ò”, “ô”, “ö”, “õ”, “ú”, “ù”, “û”, “ü”, etc. - or certain more esoteric encoded characters, some of which might cause a problem when converted. However, I don’t see any obvious problems with what you have.

All the same, in view of the filename shown later, it might be worth mentioning a fundamental difference here between the searchReplaceText and switchExtension handlers that we discussed earlier. Since the former relies on text item delimiters, it’s case sensitive - while the latter, which uses basic text manipulation, isn’t.

So (omitting the actual handler code for brevity) we could get quite different results from each subroutine:

set file_name to "test.1_3_1.MRW"

searchReplaceText(".mrw", ".jpg", file_name)
--> "test.1_3_1.MRW"

switchExtension of file_name from ".mrw" to ".jpg"
--> "test.1_3_1.jpg"

:lol::lol::lol: I sometimes ask that question of myself, too! When it comes to this technology game, I think most of us are fumbling around in the dark over some issue or other. :cool:

FileVault is a 64-bit file encryption/decryption system for more recent versions of OS X. However, it has been known to cause problems in certain situations involving file paths. From the sound of things, I’d say it’s not an issue here - I was just clutching at straws, really. You can get some more info from: http://www.apple.com/macosx/features/filevault/ - although I wouldn’t rush into using it yet…

Thanks again for that analysis. I think you may be onto something with the file type/size. My tests so far have involved only .jpg files of a fairly modest size - so it may well be that your larger files are causing GC to struggle a bit during the loading process. I had a little trouble downloading the file earlier, but I’ll try again later and see if I can run it through a few tests.

In your shoes, I’d go ahead using the delay method, too. It’s just kind of interesting when something like this crops up. Even if the technique doesn’t come through for us in this situation, it might help you elsewhere - and we should know a bit more about the limitations by the time we’re through… :wink:

My pleasure. :slight_smile:

kai wrote:

Can you identify exactly where in the script the ‘Some data was the wrong type’ error is occurring?

mreuring wrote:

On the save message, or so it seems.

I’m very late to this party and have no means to test this, but it appears as if you might be trying to save into a string… rather than a file reference.

Try:

set dest_file to destFolder & file_name
save in file dest_file as JPEG with makeCopy

This may also puke, however… just another shot in the dark.

Peter B.


Hey Peter,

I don’t immediately have the chance of testing this, but, if I would write that using alias, the script will buckle, as an alias can’t be created referencing a non-existing file, does the same limitation not count towards a file then?

However, saving, we have found, isn’t really a problem we need worry about. It’s the timing that’s the problem, can only save a file when it’s done loading. It’s a good suggestion though, I’ll most certainly play with it and keep in mind, once again, that I should really take notice of what type of ‘class’/‘type’ I’m working with.

My earlier problems with duplicating files turned out to arrise from trying to ‘tell “Finder” to duplicate…’ instead of ‘tell application “Finder” to duplicate…’. This is me coping with a language that does not have a strict syntax, I have to second-guess everything I write, the specs, nor the compiler, will tell me what I’m doing wrong.

I’ll post a cleaned up and working copy of the entire beasty I’ve come up with, if anyone wants to review and possibly test it, I’d be most gratefull :slight_smile:

Martin

I promised the full script, so, here it is:

-- Author: Martin 'Windgazer' Reurings <martin@windgazer.nl>
-- Date:	2005-05-31
-- 
-- Credits:
-- - Angus McIntyre <angus@pobox.com>, for his directoryshell.as
-- - Farid, if only for giving me hope, apart from some nice pointers
-- - kai, for sticking with me in trying to make this script behave
-- 
-- Used sources:
-- - http://www.raingod.com/raingod/resources/Systems/Macintosh/Software/AppleScripts/index.html
-- - http://bbs.applescript.net/viewtopic.php?pid=39972
--
-- LEGAL
--    
--    This software is free. It can be used and modified in any way you 
--    choose, but it may not be sold, either separately or as part of a 
--    collection without explicit prior permission from the author. The 
--    author assumes no liability for any loss, damage or mental or 
--    physical trauma you may incur through use of or inability to use 
--    this software. This disclaimer must appear on any modified or 
--    unmodified version of the software in which the name of the author
--    also appears.

-- ============================================================
-- Setting this as global property for numerous reasons, among them, laziness ;)
property destFldr : ""
property countJPG : 0
property countRAW : 0
property newline : "
"

-- Handler used when script is opened.
on run
	set countJPG to 0
	set countRAW to 0
	set theFolder to (choose folder with prompt "Choose a source folder:")
	if destFldr = "" then
		set destFldr to (choose folder with prompt "Choose a destination folder:") as text
	end if
	processObject(theFolder)
	tell application "GraphicConverter"
		quit application
	end tell
	display dialog "Converted a total of " & (countRAW + countJPG) & " images of which:" & newline & countJPG & " JPEG files" & newline & "and" & newline & countRAW & " MRW files"
end run

-- Handler used when documents are dropped onto script.
on open theObjects
	set countJPG to 0
	set countRAW to 0
	if destFldr = "" then
		set destFldr to (choose folder with prompt "Choose a destination folder:") as text
	end if
	repeat with theObject in theObjects
		processObject(theObject)
	end repeat
	tell application "GraphicConverter"
		quit application
	end tell
	display dialog "Converted a total of " & (countRAW + countJPG) & " images of which:" & newline & countJPG & " JPEG files" & newline & "and" & newline & countRAW & " MRW files"
end open

-- Stripped version of Angus' original, no longer handles
-- folders except for recursion
on processObject(theObject)
	set theInfo to info for theObject
	if theInfo is folder then
		set theContents to list folder theObject
		repeat with theItem in theContents
			set thePath to ((theObject as string) & theItem)
			processObject(thePath as alias)
		end repeat
	else
		processFile(theObject)
	end if
end processObject

-- handler: processFile
-- 
-- Process a file object. Your code, to do whatever you want
-- with the file, goes here. If you're only interested in
-- processing folders, then this can remain empty.

on processFile(this_item)
	-- Get the basics needed for processing the file.
	set modDate to modification date of (info for this_item)
	set dateFolder to destFldr & getFolderFromDate(modDate)
	set thumbFolder to dateFolder & "thumbs"
	createFolderPath(dateFolder & "original:")
	try
		alias thumbFolder
	on error --> file doesn't exist
		tell application "Finder" to make new folder at (alias dateFolder) with properties {name:"thumbs"}
	end try
	
	-- Perform the accual conversion/copy and thumbnailing.
	tell application "Finder" to set file_name to this_item's name as string
	if file_name ends with ".MRW" then
		set target_file to switchExtension of file_name from ".mrw" to ".jpg"
		set target_location to (dateFolder & "original:") as alias
		set target_file to (dateFolder & "original:" & target_file) as string
		tell application "Finder" to duplicate file this_item to folder target_location replacing yes
		convertWithGCX(this_item, target_file)
		rescale_and_save(alias target_file, 1280, alias dateFolder)
		rescale_and_save(alias target_file, 150, alias thumbFolder)
		set countRAW to countRAW + 1
	else if file_name ends with ".JPG" then
		set target_location to (dateFolder & "original:") as alias
		set target_file to ((target_location as string) & file_name) as string
		tell application "Finder" to duplicate file this_item to folder target_location replacing yes
		rescale_and_save(alias target_file, 1280, alias dateFolder)
		rescale_and_save(alias target_file, 150, alias thumbFolder)
		set countJPG to countJPG + 1
	end if
end processFile

-- convertWithGCX
-- 
-- Convert my_file to a jpeg named target_file using GraphicConverter
-- any known image type can be used, in theory...
on convertWithGCX(my_file, target_file)
	tell application "Finder" to set windowName to (my_file's name as string)
	tell application "GraphicConverter"
		set windowCount to count windows
		tell window windowName to open my_file
		--repeat while (count windows) is windowCount
		--	delay 0.2
		--end repeat
		delay 20
		save window windowName in target_file as JPEG with makeCopy without wwwready
		close window windowName
	end tell
end convertWithGCX

to rescale_and_save(this_item, target_width, target_folder)
	tell application "Image Events"
		launch
		set this_image to open this_item
		set typ to this_image's file type
		copy dimensions of this_image to {current_width, current_height}
		if current_width is greater than current_height then
			if current_width is greater than target_width then
				scale this_image to size target_width
			end if
		else
			set the new_height to target_width
			if current_height is greater than target_height then
				scale this_image to size new_height
			end if
		end if
		set target_file to (target_folder as string) & (name of this_item)
		tell application "Finder" to set new_item to target_file
		save this_image in new_item as typ
	end tell
end rescale_and_save

-- getFolderFromDate
-- 
-- Returns a string formatted to be appended to an alias, this
-- string is formatted as 'YYYY:MM:DD:' and may be apended to form
-- a file alias.
on getFolderFromDate(myDate)
	set localYear to year of myDate as text
	set tempMonth to month of myDate as number
	if tempMonth is less than 10 then
		set localMonth to "0" & (tempMonth as text)
	else
		set localMonth to tempMonth as text
	end if
	set localDay to day of myDate as text
	set dateAsFolder to (localYear & ":" & localMonth & ":" & localDay & ":")
	return dateAsFolder
end getFolderFromDate

to switchExtension of nameString from searchExt to replaceExt
	tell nameString to if it ends with searchExt then ¬
		return text 1 thru -(1 + (count searchExt)) & replaceExt
	nameString
end switchExtension

-- createFolderPath
-- 
-- My own construct, for checking, every step of the way if a path exists, and if not, create it.
on createFolderPath(folderPath)
	set oldTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set currentPath to ""
	repeat with folderPart in (folderPath's text items)
		set oldPath to currentPath
		if currentPath is equal to "" then
			set currentPath to folderPart
		else
			set currentPath to currentPath & ":" & folderPart
		end if
		try
			alias currentPath
		on error --> file doesn't exist
			tell application "Finder" to make new folder at (alias oldPath) with properties {name:folderPart}
		end try
	end repeat
	set AppleScript's text item delimiters to oldTID
end createFolderPath

So far, the only thing that bothers me is the delay. Having a fixed delay in waiting on the MRW to finish loading is ugly. Yesterday I converted about 750Mb worth of pictures from my camera (8.8Mb per MRW, not really that many pictures ;)) and it went quite alright, until it choked on the verry last picture. The screensaver kicked in, delaying the loading beyond the 20 second timeframe and blammer, timeout killed the script.

If anyone (Kai, you still with me?!?) has good alternative takes on solving this, do let me know, I’d be most interrested.

Thanx so far for everyone that peeked in and helped out!!

Martin

Hi Peter - fancy bumping in to you in this neck of the woods! :slight_smile:

Yeah - the string doesn’t look right, does it? Even GC’s AS dictionary refers to an alias:

However, GC seems to barf on pretty much anything except a string. (I know one or two other apps that behave similarly, too.) While the various delay methods that we’ve tried tend to fail for Martin, they do work for me - so I don’t think it’s the syntax we’re using that’s causing the headaches here. Worth checking, though - thanks!

Yup - still here, Martin! Just temporarily distracted… Your script is lookin’ real good, BTW! :smiley:

That collapse on the last pic is a real shame :mad: - although it tends to reinforce our reservations about a fixed delay…

Still no success downloading that MRW file, but no matter. Just thought I’d throw another idea at you, to keep you going. I believe the part on which we’re perpetually tripping appears in your ‘convertWithGCX’ handler:

I wondered whether it might be worth trying to push the ‘window count’ method in another direction - towards System Events, to be precise. I haven’t tested this (so I wouldn’t advise trying it on original files :o). However, this is roughly how I think it might look:

on convertWithGCX(my_file, target_file)
	tell application "Finder" to set windowName to (my_file's name as string)
	tell application "System Events" to set windowCount to count process "GraphicConverter"'s windows
	tell application "GraphicConverter" to open my_file
	tell application "System Events" to repeat while (count process "GraphicConverter"'s windows) is windowCount
		delay 0.2
	end repeat
	tell application "GraphicConverter"
		save window windowName in target_file as JPEG with makeCopy without wwwready
		close window windowName
	end tell
end convertWithGCX

No doubt you’ll let us know how you get on. In the meantime, I’ll continue to ponder on possible alternatives… :rolleyes:

Best wishes,

kai

Oh yeah - one other (minor) thought:

Since it can take up to 20 seconds to open a file, I wonder if it might help to extend the delay - perhaps to 1 or 2 seconds? That might free up some more cpu cycles, which I suspect GC may be gasping for at this point… :wink:

kai wrote:

Hi Peter - fancy bumping in to you in this neck of the woods!

(Lions and tigers and bears, oh my!)

Since it’s plenty dark in these woods, I might as well take another shot. I ain’t likely to hit nuthin’, am I?

mreuring wrote:

The screensaver kicked in, delaying the loading beyond the 20 second timeframe and
blammer, timeout killed the script.

If the script really timed out and threw an error to that effect, try bracketing the offending handler so:

with timeout of 360 seconds – whatever sufficient for the job…

– problem handler stuff here

end timeout

The timeout does not add a delay… only helps ensure the script can finish its work.

I’ll go quietly now.

Peter B.


Never know till you pull the trigger… :wink:

Quite. I usually go for something like an OTT timeout of 1000000 seconds (just over a week and a half). What the hell - if a job looks like it’s really going to take that long, there’s always the option of cancelling manually…

In this case, though, I believe Martin was referring to the fixed delay he’d inserted - which should have been long enough to allow GC to open a file but, unfortunately this time, wasn’t. :frowning:

That’s really the issue we’ve been trying to resolve here. If we extend the delay, the opening of every file is delayed further. If we trim it too much, we run the risk of GC returning an error (when it tries to operate on a window that doesn’t yet exist). Ideally, we want a way of pausing the script for only as long as takes to open a particular file.

The difficulty is that every idea we’ve tried to date works for me - but not for Martin (possibly because he’s dealing with larger files than I have). I’m currently trying to grab a sample of the same file type so that I can test some ideas in a way that resembles Martin’s circumstances more closely.

Nice chatting, Peter. Catch ya later. :slight_smile: