Re: Help with simple grep
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