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

|

その他のカテゴリー

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