TextEdit基本処理
| 固定リンク
| 固定リンク
| 固定リンク
| 固定リンク
NSStringEncoding | 番号 |
NSASCIIStringEncoding | 1 |
NSNEXTSTEPStringEncoding | 2 |
NSJapaneseEUCStringEncoding | 3 |
NSUTF8StringEncoding | 4 |
NSISOLatin1StringEncoding | 5 |
NSSymbolStringEncoding | 6 |
NSNonLossyASCIIStringEncoding | 7 |
NSShiftJISStringEncoding | 8 |
NSISOLatin2StringEncoding | 9 |
NSUnicodeStringEncoding | 10 |
NSWindowsCP1251StringEncoding | 11 |
NSWindowsCP1252StringEncoding | 12 |
NSWindowsCP1253StringEncoding | 13 |
NSWindowsCP1254StringEncoding | 14 |
NSWindowsCP1250StringEncoding | 15 |
NSISO2022JPStringEncoding | 21 |
NSMacOSRomanStringEncoding | 30 |
NSUTF16StringEncoding | 10 |
NSUTF16BigEndianStringEncoding | 2415919360 |
NSUTF16LittleEndianStringEncoding | 2483028224 |
NSUTF32StringEncoding | 2348810496 |
NSUTF32BigEndianStringEncoding | 2550137088 |
NSUTF32LittleEndianStringEncoding | 2617245952 |
NSProprietaryStringEncoding | 65536 |
| 固定リンク
| 固定リンク
| 固定リンク
| 固定リンク
本当はNSRTFTextDocumentTypeを使うんだろうなあ
#!/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 objFileManager to refMe's NSFileManager's defaultManager()
###ファイル名
set strFineName to "名称未設定.rtf"
###デスクトップフォルダ
set listResponse to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDesktopPathURL to (item 1 of listResponse)
###ファイルパスURL
set ocidSaveFilePathURL to ocidUserDesktopPathURL's URLByAppendingPathComponent:strFineName isDirectory:false
###ダミーのRTFのソース
set strText to "{\\rtf1\\ansi\\deff0}" as text
###Stringsにして
set ocidText to refMe's NSString's stringWithString:strText
####デスクトップに保存
set boolDone to ocidText's writeToURL:ocidSaveFilePathURL atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
| 固定リンク
昇順
#!/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
property refNSString : a reference to refMe's NSString
property refNSMutableArray : a reference to refMe's NSMutableArray
tell application "TextEdit"
tell front window
tell front document
set strContents to its text
properties
end tell
end tell
end tell
#######選択テキストを格納
set ocidText to refNSString's stringWithString:strContents
#######可変Arrayを初期化して準備
set ocidReadData to refNSMutableArray's alloc()'s initWithCapacity:0
#######改行を指定
set ocidNewlineCharacterSett to refMe's NSCharacterSet's newlineCharacterSet()
#######改行で区切りでArrayに格納
set ocidReadData to ocidText's componentsSeparatedByCharactersInSet:ocidNewlineCharacterSett
#######並び替え
###逆順に処理するのでdecendig=降順に並び替える
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:true selector:"localizedStandardCompare:"
###並べ替え
set ocidSortedArray to ocidReadData's sortedArrayUsingDescriptors:{ocidDescriptor}
###改行入れてテキスト化
set ocidSortedString to ocidSortedArray's componentsJoinedByString:"\n"
####テキスト化
set strSortedContants to ocidSortedString as text
####テキストエディターに内容を戻す
tell application "TextEdit"
tell front window
tell front document
set its text to strSortedContants
end tell
end tell
end tell
降順
#!/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
property refNSString : a reference to refMe's NSString
property refNSMutableArray : a reference to refMe's NSMutableArray
tell application "TextEdit"
tell front window
tell front document
set strContents to its text
properties
end tell
end tell
end tell
#######選択テキストを格納
set ocidText to refNSString's stringWithString:strContents
#######可変Arrayを初期化して準備
set ocidReadData to refNSMutableArray's alloc()'s initWithCapacity:0
#######改行を指定
set ocidNewlineCharacterSett to refMe's NSCharacterSet's newlineCharacterSet()
#######改行で区切りでArrayに格納
set ocidReadData to ocidText's componentsSeparatedByCharactersInSet:ocidNewlineCharacterSett
#######並び替え
###逆順に処理するのでdecendig=降順に並び替える
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:false selector:"localizedStandardCompare:"
###並べ替え
set ocidSortedArray to ocidReadData's sortedArrayUsingDescriptors:{ocidDescriptor}
###改行入れてテキスト化
set ocidSortedString to ocidSortedArray's componentsJoinedByString:"\n"
####テキスト化
set strSortedContants to ocidSortedString as text
####テキストエディターに内容を戻す
tell application "TextEdit"
tell front window
tell front document
set its text to strSortedContants
end tell
end tell
end tell
| 固定リンク
#!/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
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refNSMutableArray : a reference to refMe's NSMutableArray
property refNSWorkspace : a reference to refMe's NSWorkspace
#########################
####前面の書類から必要な情報を取得
#########################
tell application "TextEdit"
activate
tell front document
set strFileName to name as text
set strFilePath to path as text
end tell
end tell
if strFilePath is "" then
log "このファイルは未保存なのでデスクトップに保存します"
set strFilePath to ("~/Desktop/" & strFileName) as text
end if
####ファイル名から拡張子取ってベースファイル名
set ocidFileName to refNSString's stringWithString:strFileName
set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension()
###パスからファイル名を取って保存先パスを調べる
set ocidFilePathStr to refNSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
###コンテナフォルダ(保存先のフォルダパス)
set ocidContainerDirPath to ocidFilePath's stringByDeletingLastPathComponent()
#########################
####ダイアログ
#########################
set listChooser to {"Doc\tcom.microsoft.word.doc", "XML\tcom.microsoft.word.wordml", "DOCX\torg.openxmlformats.wordprocessingml.document", "ODT\torg.oasis-open.opendocument.text", "HTML\tpublic.html", "WEBARCHIVE\tcom.apple.webarchive", "RTFD\tcom.apple.rtfd", "RTF\tpublic.rtf"} as list
try
tell current application
activate
set listResponse to (choose from list listChooser with title "保存形式を選んでください" with prompt "保存形式を選んでください" default items (item 1 of listChooser) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
end tell
on error
log "エラーしました"
return "エラーしました"
error "エラーしました" number -200
end try
####multiple selections allowed falseの場合
if listResponse is false then
return "キャンセルしましたA"
error "キャンセルしました" number -200
####multiple selections allowed用
else if (item 1 of listResponse) is false then
return "キャンセルしましたB"
error "キャンセルしました" number -200
end if
#########################
####本処理
#########################
repeat with itemResponse in listResponse
###戻り値をタブでリストにする
set ocidItemTextArray to (refNSMutableArray's alloc()'s initWithCapacity:0)
set ocidDelimiters to ((refMe's NSCharacterSet)'s characterSetWithCharactersInString:"\t")
set ocidItemResponse to (refNSString's stringWithString:itemResponse)
set ocidItemTextArray to (ocidItemResponse's componentsSeparatedByCharactersInSet:ocidDelimiters)
###リストの1つ目が拡張子
set ocidFirstObject to ocidItemTextArray's firstObject()
###小文字に
set ocidExetensionName to ocidFirstObject's lowercaseString()
set strExetensionName to ocidExetensionName as text
#####保存用のファイル名を整形
set ocidNewFileName to (ocidBaseFileName's stringByAppendingPathExtension:strExetensionName)
####コンテナにファイル名追加して保存先パス
set ocidFilePath to (ocidContainerDirPath's stringByAppendingPathComponent:ocidNewFileName)
###テキスト形式に戻す
set strSaveFilePath to ocidFilePath as text
tell application "TextEdit"
activate
tell front document
activate
save in (POSIX file strSaveFilePath)
end tell
end tell
end repeat
#########################
####処理終了
#########################
###コンテナディレクトリ(保存先)をNSURLにして
set ocidFilePathURL to refNSURL's alloc()'s initFileURLWithPath:ocidContainerDirPath isDirectory:true
###Finderで開く
set ocidShardWorkspace to refNSWorkspace's sharedWorkspace()
ocidShardWorkspace's openURL:ocidFilePathURL
tell application "Finder" to activate
return
| 固定リンク
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 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