• 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 label from a record (solution)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting label from a record (solution)


  • Subject: Re: Getting label from a record (solution)
  • From: EBI Aktivitet <email@hidden>
  • Date: Tue, 18 Nov 2003 16:22:07 +0100

Sorry for posting such a long script, but since I got it working, and there
seems to be no simple trick to get a label from a property, well, here we
go:

Thanks to Michelle and Kai for your help, it was well needed!

OK, so this script will get you the class names of the properties for a
document. I've included two (actually three) ways of doing this, and you
have a choice of <<class>>, or plain text.

Note that the two different alternatives don't return the same result, since
they are dependant on how the error result, from which they are extracted,
is formatted.


Regards, Adim


----Script----

tell application "Adobe Photoshop CS"
set theResult to properties of document 1

try
get item 5000 of theResult
--Create error by asking for something unreasonable

on error errmsg_plain_text
--tell me to display dialog errmsg_plain_text
end try

try
set theResult to (theResult as string)
--Create error by asking for impossible conversion

on error errmsg_as_class
--tell me to display dialog errmsg_as_class
end try

end tell

GetTheClass(errmsg_as_class) --Will get class, as class, and as plain text
GetTheClassAsText(errmsg_plain_text) --Will get class as plain text



on GetTheClass(errorMessage)

set theClassAsText to ""
set theClass to ""
set CharCount to (count characters in errorMessage)
set i to 1

repeat while i is less than CharCount

set theText to ""

if "+" is in character i of errorMessage then
set theCode to (character i of errorMessage)

set c to 1
repeat 20 times
-- Repeat more than you need, exit is in the repeat loop anyway

set theText to theText & character i of errorMessage
if character i of errorMessage is ";" then exit repeat
--We got the class, so exit

set i to i + 1

end repeat

set tempClass to theText as string
set tempClassAsText to run script tempClass
--call the class, so we get plain text

set theClass to theClass & tempClass & return
set theClassAsText to theClassAsText & tempClassAsText & return

end if
set i to i + 1
end repeat

display dialog theClass
display dialog theClassAsText

end GetTheClass

on GetTheClassAsText(errorMessage)

set theClassAsText to ""
set CharCount to (count characters in errorMessage)
set i to 1
set theFirstDoneFlag to false
--Flag to check that we dont get bogus classes, if { exists in filenames

repeat while i is less than CharCount

set theText to ""

if ("{" is in character i of errorMessage) and (":" is not in
character (i - 1) of errorMessage) then
set i to i + 1

repeat 500 times
-- Repeat more than you need, exit is in the repeat loop anyway

if (character i of errorMessage is ":") or (character i of
errorMessage is ",") then exit repeat
set theText to theText & character i of errorMessage

set i to i + 1

end repeat

if theFirstDoneFlag is false then
set tempClassAsText to theText as string
set theClassAsText to theClassAsText & tempClassAsText &
return
end if

set theFirstDoneFlag to true

else if ("," is in character i of errorMessage) and (" " is in
character (i + 1) of errorMessage) then

set i to i + 2
set theListFlag to false
--Flag to make sure we don't check lists in the record

repeat 500 times
-- Repeat more than you need, exit is in the repeat loop anyway

if character i of errorMessage is ":" then exit repeat
if character i of errorMessage is "," then
set theListFlag to true
exit repeat
end if
set theText to theText & character i of errorMessage

set i to i + 1

end repeat

if theListFlag is false then
set tempClassAsText to theText as string
set theClassAsText to theClassAsText & tempClassAsText &
return
end if
end if
set i to i + 1
end repeat
display dialog theClassAsText

end GetTheClassAsText


----End script----
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Getting label from a record (part 1) (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: Getting label from a record
  • Next by Date: Re: D'oh-plicate terminology
  • Previous by thread: Re: Getting label from a record
  • Next by thread: Mount Volume
  • Index(es):
    • Date
    • Thread