• 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: Help with simple grep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with simple grep


  • Subject: Re: Help with simple grep
  • From: Jon Pugh <email@hidden>
  • Date: Fri, 29 Aug 2008 11:10:54 -0700

At 10:47 AM -0700 8/29/08, Joe wrote:
>I would like to return only the numeric portion of the string produced by the following script. The example returns "return character, space character, 188" and I'm looking for just "188"

set pth to alias "D1:Users:joe:Pictures:Photos-Scans:500.jpg"
tell application "Finder" to set x to POSIX path of pth
set y to do shell script "mdls -name kMDItemPixelHeight " & quoted form of x
tell SmartString
	setString(y)
	afterString("= ")
end tell

Avoid that obtuse grep stuff.  Use AppleScript.  Check out my SmartString object which does all kinds of easy and understandable string manipulation.

http://www.seanet.com/~jonpugh/software/SmartString.applescript

It includes all these routines:

	getString() --> string (only reads)
	setString(aString)
	setList(aList, seperator)

	subString(x, y) --> string (only reads)
	beforeString(subString) --> string (only reads)
	afterString(subString) --> string (only reads)
	betweenStrings(afterThis, beforeThis) --> string (only reads)

	appendString(aString) --> string
	prependString(aString) --> string
	insertBefore(subString, thisString) --> string
	insertAfter(subString, thisString) --> string

	deleteCharacters(x, y) --> string
	deleteString(subString) --> string
	deleteBefore(beforeString) --> string
	deleteAfter(afterString) --> string
	deleteBetween(beforeThis, afterThis) --> string

	keepBefore(beforeString) --> string
	keepAfter(afterString) --> string
	keepBetween(beforeThis, afterThis) --> string
	replaceString(subString, withString) --> string
	replaceStrings(subString, withString) --> string
	replaceBetween(frontTag, rearTag, newValue) --> string

	getTokens(delim) --> list (only reads)

	firstToken(delim) --> string (only reads)
	deleteFirstToken(delim)
	keepFirstToken(delim)

	lastToken(delim) --> string (only reads)
	deleteLastToken(delim)
	keepLastToken(delim)

	NthToken(n, delim) --> string (only reads)
	deleteNthToken(n, delim)
	keepNthToken(n, delim)

	trimWhitespace()
	uppercase()
	lowercase()

Nasty old grep is better for munching lots of strings, not a single one.  ;)

Jon
 _______________________________________________
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

References: 
 >Help with simple grep (From: Joe <email@hidden>)

  • Prev by Date: Re: Help with simple grep
  • Next by Date: Re: Help with simple grep
  • Previous by thread: Re: Help with simple grep
  • Next by thread: Re: Help with simple grep
  • Index(es):
    • Date
    • Thread