• 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
Quoting URLs for the Shell
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Quoting URLs for the Shell


  • Subject: Quoting URLs for the Shell
  • From: Christopher Stone <email@hidden>
  • Date: Tue, 02 Oct 2012 05:27:50 -0500

Hey Folks,

I use cURL a lot and sometimes Wget for various tasks, and occasionally I forget whether my handlers take quoted strings for input or not.  So I decided that rather than force input to be quoted or unquoted I'd write a little routine to make them ambivalent.

------------------------------------------------------------------------------
# For a single url.
------------------------------------------------------------------------------
tell _url
  if (character 1 = character -1) and (character 1 is in {"\"", "'"}) then
    # Continue
  else
    set _url to "\"" & _url & "\""
  end if
end tell

------------------------------------------------------------------------------
# For an Applescript list of urls.
------------------------------------------------------------------------------
if class of linkList = list and linkList ≠ {} then
  repeat with _url in linkList
    tell _url
      if (character 1 = character -1) and (character 1 is in {"\"", "'"}) then
        # Continue
      else
        set contents of _url to "\"" & _url & "\""
      end if
    end tell
  end repeat
end if
------------------------------------------------------------------------------

On my system I prefer to use the Satimage.osax's regex which is fast as all get-out and quite convenient.

set linkList to change "(^[\"']*|[\"']*$)" into "\"" in linkList with regexp

This will operate on a string or a list of strings and requires no separate test for quoting.

I always try to have a vanilla or shell backup for portability though, so I wonder if anyone has a better way?

--
Best Regards,
Chris

 _______________________________________________
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

  • Prev by Date: Re: Referencing a Message in Mail 6.1 - Huh?
  • Next by Date: Re: Referencing a Message in Mail 6.1 - Huh?
  • Previous by thread: DropBox Toggle
  • Next by thread: regex in Satimage OSAX doesn't work the way I expected
  • Index(es):
    • Date
    • Thread