AppleScript NSCharacterSet

[whitespaceAndNewlineCharacterSet]行頭行末の余分な改行を取る


#!/usr/bin/env osascript

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

#

#

#

#

# com.cocolog-nifty.quicktimer.icefloe

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

##自分環境がos12なので2.8にしているだけです

use AppleScript version "2.8"

use framework "Foundation"

use scripting additions


property refMe : a reference to current application




set strText to "\n\n\nHi\n\nHow are you\nToday.\n\n\n\n"


set ocidText to refMe's NSString's stringWithString:strText


set ocidText to ocidText's stringByTrimmingCharactersInSet:(refMe's NSCharacterSet's whitespaceAndNewlineCharacterSet)


log ocidText as text

(*Hi


How are you

Today.*)

|

[NSCharacterSet] stringByAddingPercentEncodingWithAllowedCharacters(%エンコード)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString

## set text
set strURL to "http://foo bar/" as text

##Make NSString
set ocidNSString to objNSString's stringWithString:strURL
log ocidNSString as text
log ocidNSString's className() as text

##set URLPathAllowedCharacterSet
set ocidNSCFCharacterSet to objMe's NSCharacterSet's URLPathAllowedCharacterSet()
log ocidNSCFCharacterSet's className() as text

### Do Percent Encoding
set ocidEncodedURL to ocidNSString's stringByAddingPercentEncodingWithAllowedCharacters:ocidNSCFCharacterSet
log ocidEncodedURL as text
log ocidEncodedURL's className() as text

return ocidEncodedURL as text
















#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString

## set text
set strURL to "http://foo bar/" as text

##Make NSString
set ocidNSString to objNSString's stringWithString:strURL
log ocidNSString as text
log ocidNSString's className() as text

##set URLUserAllowedCharacterSet
set ocidNSCFCharacterSet to objMe's NSCharacterSet's URLUserAllowedCharacterSet()
log ocidNSCFCharacterSet's className() as text
(*
URLPathAllowedCharacterSet
URLFragmentAllowedCharacterSet
URLHostAllowedCharacterSet
URLPasswordAllowedCharacterSet
URLQueryAllowedCharacterSet
URLUserAllowedCharacterSet
*)

### Do Percent Encoding
set ocidEncodedURL to ocidNSString's stringByAddingPercentEncodingWithAllowedCharacters:ocidNSCFCharacterSet
log ocidEncodedURL as text
log ocidEncodedURL's className() as text

return ocidEncodedURL as text
















#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

[newlineCharacterSet]文字列の中の改行を削除(行頭、行末)

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString



set ocidText to objNSString's stringWithString:"A\nB\rC\n\rD"
-->この配列だと削除できない

set ocidText to objNSString's stringWithString:"\n\n\nABCD"

set ocidText to objNSString's stringWithString:"\n\n\nABCD\r\r\r"

set ocidText to objNSString's stringWithString:"ABCD\n\r\n\r\n\r"


set ocidNSCFCharacterSet to objMe's NSCharacterSet's newlineCharacterSet()

set ocidTaggedPointerString to ocidText's stringByTrimmingCharactersInSet:ocidNSCFCharacterSet

log ocidTaggedPointerString
log ocidTaggedPointerString as text
log className() of ocidTaggedPointerString as text

|

[whitespaceCharacterSet]文字列の中のタブを削除(行頭、行末)

出来ない配列もありますので使用には留意が必要…つーか使えない…
要は行頭、行末のタブを削除が正しいか?

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString



set ocidText to objNSString's stringWithString:"A\tB\tC\tD"
-->この配列だと削除できない

set ocidText to objNSString's stringWithString:"\t\t\tABCD"

set ocidText to objNSString's stringWithString:"ABCD\t\t\t"

set ocidText to objNSString's stringWithString:"\t\t\tABCD\t\t\t"



set ocidNSCFCharacterSet to objMe's NSCharacterSet's whitespaceCharacterSet()

set ocidTaggedPointerString to ocidText's stringByTrimmingCharactersInSet:ocidNSCFCharacterSet

log ocidTaggedPointerString
log ocidTaggedPointerString as text
log className() of ocidTaggedPointerString as text

|

[decimalDigitCharacterSet]文字列の中の数値を削除

数値=数値のみで形成されている文字列のみ
NG: 1A2B3C4D6E-->この形式の場合はalphanumericCharacterSetで削除する
OK: 1234

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString


set ocidText to objNSString's stringWithString:"1A2B3C4D6E"
-->この形式の場合はalphanumericCharacterSetで削除する

set ocidText to objNSString's stringWithString:"1234"

set ocidNSCFCharacterSet to objMe's NSCharacterSet's decimalDigitCharacterSet()

set ocidTaggedPointerString to ocidText's stringByTrimmingCharactersInSet:ocidNSCFCharacterSet

log ocidTaggedPointerString
log ocidTaggedPointerString as text
log className() of ocidTaggedPointerString as text

|

[uppercaseLetterCharacterSet]文字列の中の英字の大文字を削除

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString


set ocidText to objNSString's stringWithString:"abcdefg1234HIJKLMN"

set ocidNSCFCharacterSet to objMe's NSCharacterSet's uppercaseLetterCharacterSet()

set ocidTaggedPointerString to ocidText's stringByTrimmingCharactersInSet:ocidNSCFCharacterSet

log ocidTaggedPointerString
log ocidTaggedPointerString as text
log className() of ocidTaggedPointerString as text

|

[lowercaseLetterCharacterSet]文字列の中の英字の小文字を削除

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString


set ocidText to objNSString's stringWithString:"abcdefg1234HIJKLMN"

set ocidNSCFCharacterSet to objMe's NSCharacterSet's lowercaseLetterCharacterSet()

set ocidTaggedPointerString to ocidText's stringByTrimmingCharactersInSet:ocidNSCFCharacterSet

log ocidTaggedPointerString
log ocidTaggedPointerString as text
log className() of ocidTaggedPointerString as text

|

[letterCharacterSet]文字列の中の英字を削除

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString


set ocidText to objNSString's stringWithString:"abcdefg1234HIJKLMN"

set ocidNSCFCharacterSet to objMe's NSCharacterSet's letterCharacterSet()

set ocidTaggedPointerString to ocidText's stringByTrimmingCharactersInSet:ocidNSCFCharacterSet

log ocidTaggedPointerString
log ocidTaggedPointerString as text
log className() of ocidTaggedPointerString as text

|

[alphanumericCharacterSet]文字列の中の数字を削除

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat


property objMe : a reference to current application
property objNSString : a reference to objMe's NSString


set ocidText to objNSString's stringWithString:"04-Jan-13"

set ocidNSCFCharacterSet to objMe's NSCharacterSet's alphanumericCharacterSet()

set ocidTaggedPointerString to ocidText's stringByTrimmingCharactersInSet:ocidNSCFCharacterSet

log ocidTaggedPointerString
log ocidTaggedPointerString as text
log className() of ocidTaggedPointerString as text

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom