Issue #89
Today I find that AppleScript
allows us to import Foundation
, with that we have lots of power, including NSString
. See my script
use scripting additions
use framework "Foundation"
property NSString : a reference to current application's NSString
Here is how I can remove last path component from a string
on myRemoveLastPath(myPath)
set myString to NSString's stringWithString:myPath
set removedLastPathString to myString's stringByDeletingLastPathComponent
removedLastPathString as text
end myRemoveLastPath
You need to cast to NSString
with NSString's stringWithString:
and cast back to Apple Script string with as text
. The 's
is how you can invoke functions.
One more thing is that we can support parameters to function, like this script
on remove:remove_string fromString:source_string
set s_String to NSString's stringWithString:source_string
set r_String to NSString's stringWithString:remove_string
return s_String's stringByReplacingOccurrencesOfString:r_String withString:""
end remove:fromString: