• 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: Convert URL to text?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert URL to text?


  • Subject: Re: Convert URL to text?
  • From: kai <email@hidden>
  • Date: Sat, 3 Dec 2005 19:26:40 +0000


On 3 Dec 2005, at 14:24, Scott Dunn wrote:

I'm trying to write a small utility that performs some actions based upon the URL of the current web page. I assumed that the following would give me a variable of the correct type for searching the keychain, however it appears I'm wrong. If I hard- code 'keyName' to the address of the page then the retrieval works fine.

tell application "Safari"
	set theURL to the URL of document 1
end tell
set keyName to theURL as text
-- at this point 'keyName' seems to be correct, but doesn't work.
-- if I 'set keyName to "www.apple.com"' then it works

I'm assuming that the coercion of URL to text is not working as I expect and 'keyName' actually contains some extraneous non-visible characters.

You're right, Scott. Safari returns theURL as Unicode text, and the coercion to text/string, while returning a class of string, actually results in international/styled text. In other words, the text still retains some encoding. Since there are several ways to strip this from the text, here's a selection:


------------------

set {text:keyName} to theURL as text

------------------

set keyName to theURL as string as record as list as string

------------------

set keyName to (theURL as string as record)'s «class ktxt»

------------------

Incidentally, while it used to be possible to coerce Unicode text to a record directly, this is evidently no longer the case. However, initially coercing to a string still seems to work...

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Convert URL to text?
      • From: Emmanuel <email@hidden>
References: 
 >Re: Fwd: Validating email address (From: has <email@hidden>)
 >Convert URL to text? (From: Scott Dunn <email@hidden>)

  • Prev by Date: Re: Convert URL to text?
  • Next by Date: Re: Convert URL to text?
  • Previous by thread: Re: Convert URL to text?
  • Next by thread: Re: Convert URL to text?
  • Index(es):
    • Date
    • Thread