• 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: TIDs info summary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TIDs info summary


  • Subject: Re: TIDs info summary
  • From: Paul Skinner <email@hidden>
  • Date: Mon, 11 Nov 2002 16:57:16 -0500

On Monday, November 11, 2002, at 01:19 PM, bill fancher wrote:


On Saturday, November 9, 2002, at 08:09 PM, Paul Skinner wrote:

The following example script uses two nested handlers. AsciiSort and GetHREFs. Both of these handlers change the TIDs to do work, both of them store and restore the TIDs. If they did not, this would break and require more lines to accomplish the same functions.

set AppleScript's text item delimiters to "/"
text item -1 of (item 1 of (AsciiSort(GetHREFs((read file ((choose file) as text))))))
-->"radio.weblogs.com:0103146:.webloc"

Would you agree that in THIS case I needed to store and restore the TIDs?

I'm having trouble picturing the situation. Could you provide a minimal example that might help me out (or the actual code, or perhaps a pointer to where I might find AsciiSort and GetHREFs online)?

Sure. This is simpler and shows the gist of my point.
When you try to use the output of a handler as an argument without assigning it to a variable, you have to use whatever TIDs are in effect when the handler completes. In this case, I wanted to use ":" but they get changed to "" by the handler. To avoid this I could assign the result of the handler to a variable and set the TIDs again and then do the text item part.
To avoid this additional code I could just store and restore the TIDs within the replace handler. This is also additional code. You might argue that one is as good as the other, but one I don't have to code each time I use the replace handler.


--I want to get the disk of a path. The path has Unix delimiters.

set AppleScript's text item delimiters to ":"
text item 1 of (replace("disk/folder/subfolder/file", "/", ":"))
-->"d" : ( I wanted "disk".


on replace(textString, oldCharacter, newCharacter)
--replace the slashes with colons.
set output to {}
repeat with thischaracter in the characters of textString
set thischaracter to contents of thischaracter
if thischaracter is oldCharacter then
set the end of output to newCharacter
else
set the end of output to thischaracter
end if
end repeat
set AppleScript's text item delimiters to ""
return output as string
end replace


I don't generally invest much "ego" in these sorts of things, and will gladly admit to being wrong (publicly, on-list)

I don't think that you are wrong. Your understanding of the TIDs seems to match mine. Your choice of action in response to that knowledge is different than mine.

, but I'm just not sure why more code might be needed. (Perhaps I should say "significantly more". I can picture some exceptional situations where you'd need a few extra lines, but that hardly outweighs the extra code needed to always and everywhere restore tid's.)

My main intent in declaring myself an outlaw was to alert people to the danger of assuming that code would always and everywhere leave tid's as it found them, or that you could count on the "default" at the beginning of script or anywhere else.
snip
--
bill
snip

Good reason. Ignorance is really bad. Anything that removes ignorance is better than a thing that does not. (my opinion.)
On the other hand, one might also use this argument to steal everything not locked down and declare that you are trying to educate people on the possibility of theft.
--
Paul Skinner
_______________________________________________
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.
  • Prev by Date: Acrobat Bookmarks in OsX
  • Next by Date: Re: applescript-users digest, Vol 3 #1049 - 11 msgs
  • Previous by thread: RE:Acrobat Bookmarks in OsX
  • Next by thread: Re: applescript-users digest, Vol 3 #1049 - 11 msgs
  • Index(es):
    • Date
    • Thread