• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: getting height x width of image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting height x width of image


  • Subject: Re: getting height x width of image
  • From: TjL <email@hidden>
  • Date: Wed, 20 Jun 2007 15:24:57 -0400


On Jun 20, 2007, at 3:12 PM, Mark J. Reed wrote:

screenshot-344x208-2007-06-20_14.39.57.png

Kayo. I would use something other than periods in the time, though. Colons are bad from an HFS perspective, of course, but filenames with multiple periods can also confuse some things. Maybe more dashes.

Haven't had any problems with multiple . in OS X. Windows, yes....


set theDate to do shell script "/bin/date \"+%Y-%d-%m_%H.% M.%S\"" --
get the date string
-- is there a better way to get the date w/o using a shell script?

That depends on how you define "better". There are certainly ways to get a formatted date string within AppleScript without calling out to the shell, but they tend to be more verbose (unless you have an OSAX with a feature designed for the purpose).


better = less CPU intensive, or, really, "faster" but it doesn't much matter as this seems fast enough and isn't used all that often


repeat with x in added_items
--you always get a list, even if it's one file, so we loop through
the list here
set theFile to x --x is just a list placeholder, let's use a better
name for what x refers to

Well, that's kind of silly. Why not just do

          repeat with theFile in added_items

in the first place?

That was part of a copy/paste from another script I found :-)


tell application "Finder" --since we're manipulating files, we use
the Finder

You can do a lot of file manipulation directly, without having to get the Finder involved. Depends on what you're doing.

ditto

try
tell application "Image Events"
-- start the Image Events application
launch
-- open the image file
set theFile to open theFile

That doesn't work IMM. The open command in Image Events takes a pathname, not a file object.

It's also a bad idea to reuse "theFile"as both the file object and the
image object; in fact, that's probably the source of your
difficulties.  Settting the name of the image object doesn't rename
the file on disk, and Preview doesn't know what to do with the image
object either.

Try this:

tell application "Image Events"
   set theImage to open (theFile as string)
   copy dimensions of theImage to {W, H}
end

set the name of theFile to "screenshot-"& W & "x" & H & "-" & theDate
& "." & theFileExtension

that works (*) except that you have to tell Image Events to launch (I dunno why, you'd think it'd be implied since you wanted to use it, but all the examples I saw used it), so I put it like this:


tell application "Image Events"
	launch
	set theImage to open (theFile as string)
	copy dimensions of theImage to {W, H}
end tell

which left me with a filename like this:

	screenshot-344.0x87.0-2007-06-20_15.18.30.png


Could I be potentially rude and ask another question/favor?

Rather than 344.0x87.0 is there a way to drop the .0 so it's just 344x87?

THANKS!  This is already much better than what I had.

	TjL


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: getting height x width of image
      • From: Michelle Steiner <email@hidden>
    • Re: getting height x width of image
      • From: "Mark J. Reed" <email@hidden>
References: 
 >getting height x width of image (From: TjL <email@hidden>)
 >Re: getting height x width of image (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: getting height x width of image
  • Next by Date: Re: satimage OSAX list folder problem
  • Previous by thread: Re: getting height x width of image
  • Next by thread: Re: getting height x width of image
  • Index(es):
    • Date
    • Thread