getting dimensions of images and pasting into a text file

Merci Yvan,

The second one works perfectly! I have never scripted System Events before.

This solution is still calling the application “System Events” and seems a little longer and more complex (to me!;))than:-

set f to POSIX path of (choose file)
set justName to do shell script "basename " & quoted form of f & " | rev | cut -d'.' -f2-20 | rev"

Which achieves the same thing.

Thank you for your comments though. I will take a look at “System Events”

Hello

I built a kind of race.

Test #1 :


set f to POSIX path of (choose file)
set beg to current date
repeat 1000 times
	repeat 1000 times
		set justName to do shell script "basename " & quoted form of f & " | rev | cut -d'.' -f2-20 | rev"
	end repeat
end repeat
set fin to current date
fin - beg
-->10262

Test #2


set f to POSIX path of (choose file)
set beg to current date
repeat 1000 times
	repeat 1000 times
		tell application "System Events" to tell disk item (f as text)
			set fName to name
			name extension
		end tell
		set type to result
		if type is "" then
			set bareName to fName
		else
			set bareName to text 1 thru -((count of type) + 2) of fName
		end if
	end repeat
end repeat
set fin to current date
fin - beg
--> 3898

My « long » script run 2.6 times faster than your « short » one :slight_smile:

Now I’m waiting for an enhanced version of ASObjC Runner delivering the bareName among other properties.

Yvan KOENIG (VALLAURIS, France) lundi 23 avril 2012 17:00:07

Hi again Yvan,

I too have just tested both of your ‘race’ scripts and get very different results.

I started with your ‘long’ (but quicker!) script. After several Hours! it was still running :/. So I changed the repeats to:

repeat 100 times
	repeat 10 times

This time your 'System Events" version gave the result “39”
My “Shell” version gave the result “9” !! (4.333 times quicker)

I wonder why the same scripts should differ so between two systems? I am running Mac OS Leopard. Has Lion become that much quicker?

Regards.

The long time was deliberate.
I ran the test under 10.7.3
When your script was in use, I wasn’t in front of the mac so, only the script was at work.

When I ran mine, I was busy on the machine

Calling System Events always introduce an important extraneous time.
This is why some of us choose to use OSAXen like Satimage or, even better for available features, the late release of Shane Stanley’s ASObjC Runner.app
On my machine, it’s ran once during the startup process so it’s immediately available when a script must use one of its features.

Yvan KOENIG (VALLAURIS, France) lundi 23 avril 2012 19:22:22

It’s possible, although this case seems extreme. My (Lion) figures with your shorter tests show the shell method taking about 1.5 times as long. But there are lots of variables in these sorts of tests (and the time taken for System Events to launch).

There is one thing to keep in mind, though: size of code has no bearing on speed of execution. So this method will be considerably quicker than either of the others, by a large factor:

set f to POSIX path of (choose file)
set beg to current date
repeat 10 times
	repeat 100 times
		set saveTID to AppleScript's text item delimiters
		set AppleScript's text item delimiters to {"/"}
		set theName to text item -1 of f
		set AppleScript's text item delimiters to {"."}
		set bareName to text 1 thru text item -2 of theName
		set AppleScript's text item delimiters to saveTID
	end repeat
end repeat
set fin to current date
fin - beg

On the other hand, speed isn’t everything…

Thanks Yvan and Shane,

I have to agree Shane, Speed is not everything and thinking about it, the speed at which each of these scripts get the “basename” less extension on one file, is probably negligible. Having said that, your “text item delimiter” version, even repeating 100 times (twice), is way faster. Worth baring in mind for future projects, especially when ‘batch’ processing.

Thanks again.