• 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: Scott Dunn <email@hidden>
  • Date: Sun, 4 Dec 2005 15:50:34 -0500


On Dec 4, 2005, at 1:02 PM, has wrote:

Scott Dunn wrote:

I'm trying to write a small utility that performs some actions based
<snip>

Are you certain you actually need the URL as a string? Did you try passing keychain the original Unicode text value? While it's not unknown for some gnarly old pre-OS X applications to throw a fit when passed anything but a string, the vast majority should have no problem as they'll have the Apple Event Manager to coerce the given value to their desired type when retrieving it.



Had I been able to retrieve the key using the URL then I wouldn't have had a problem! Unfortunately the URL is of type 'utxt', at least that's what is displayed if I do 'display dialog class of theURL' and I get an error from 'Keychain Scripting' if I use that type to retrieve a key.



-- if I 'set keyName to "www.apple.com"' then it works

Here's a wild guess: you haven't checked to see what the URL strings returned by Safari actually look like. Might be a good idea to do so before assuming your problem's due to a type issue. If your Keychain keys are domain names, you'll need to extract those from the URL strings returned by Safari first.

Sorry, your guess is wrong ;-) I did check the URL strings. The URL displays correctly if I do 'display dialog theURL'. If I hard-code my keyname to 'www.apple.com' then the key retrieval works fine. If I use the URL, or more correctly a substring of the URL as I need to extract the server/domain from the URL, then it doesn't work. Which lead me to believe there was a type coercion issue. As it turns out, the earlier suggestion from Kai (set {text:keyName} to theURL as text) worked perfectly. Thanks Kai! Being new to AppleScript I had no idea that strings could have different underlying representations so even though my debug dialogs were displaying the exact same values, the actual key retrieval was broken until I stopped using unicode text (I assume that is what utxt is). Anyway, to summarise for anyone else that may follow...


The following (and countless variations!), does NOT work:
tell application "Safari"
set theURL to the URL of document 1
set theServer to theURL as text
-- nasty way to extract server name, any better way?
set theServer to text ((offset of ":" in theServer) + 3) through length of theServer
set theServer to text 1 through ((offset of "/" in theServer) - 1) of theServer
tell application "Keychain Scripting"
set thiskey to the first key of current keychain whose name is theServer
end tell
end tell


but this does...
And thisaa t tell application "Safari"
set theURL to the URL of document 1
set {text:theServer} to theURL as text
-- nasty way to extract server name, any better way?
set theServer to text ((offset of ":" in theServer) + 3) through length of theServer
set theServer to text 1 through ((offset of "/" in theServer) - 1) of theServer
tell application "Keychain Scripting"
set thiskey to the first key of current keychain whose name is theServer
end tell
end tell


Thanks to all for taking the time to respond.

Scott.
_______________________________________________
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


References: 
 >Re: Convert URL to text? (From: has <email@hidden>)

  • Prev by Date: Re: Validating email address
  • Next by Date: Re: Validating email address -- What are the allowed chars?
  • Previous by thread: Re: Convert URL to text?
  • Next by thread: Re: Convert URL to text?
  • Index(es):
    • Date
    • Thread