[CotEditor]文字コード変換(HTML用)
| 固定リンク
| 固定リンク
| 固定リンク
| 固定リンク
| 固定リンク
| 固定リンク
Applescriptでの処理は、考えすぎ…ヤリすぎは禁物です。
ある程度『現状』にあった方法でやっておいて
後でが良いようだ
| 固定リンク
#!/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
####設定項目
##UTI
set strUTI to "com.apple.Safari" as text
##指定拡張子
set strExtension to "html" as text
(*
主要なUTI
"com.apple.Safari"
"com.google.Chrome"
"com.microsoft.edgemac"
"org.mozilla.firefox"
"com.operasoftware.Opera"
"com.vivaldi.Vivaldi"
"com.brave.Browser"
"org.chromium.Chromium"
*)
tell application "CotEditor"
set numCntActvDoc to (count of document) as integer
if numCntActvDoc = 0 then
return "ドキュメントがありません"
end if
tell front document
log "処理開始"
end tell
set aliasFilePath to (file of front document) as alias
end tell
set strFilePath to POSIX path of aliasFilePath as text
#####パスのString
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
#####パスにして
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
###URLに
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath
#####拡張子を取得
set ocidExtensionName to ocidFilePath's pathExtension()
#####小文字にして
set ocidExtensionNameLC to ocidExtensionName's lowercaseString()
####テキストで確定しておく
set strExtensionName to ocidExtensionNameLC as text
####拡張子がHTMLなら
if strExtensionName is strExtension then
####UTIからアプリケーションのパスを求める
set ocidWorkspace to refMe's NSWorkspace's sharedWorkspace()
set ocidAppPathURL to ocidWorkspace's URLForApplicationWithBundleIdentifier:strUTI
if ocidAppPathURL is (missing value) then
tell application "Finder"
###UTIからアプリケーションのパスを取得
set fileAppPath to application file id strUTI
###エリアス
set aliasAppPath to fileAppPath as alias
###UNIXパス
set strAppPath to POSIX path of aliasAppPath as text
set ocidAppBundlePathStr to (refMe's NSString's stringWithString:strAppBundlePath)
set ocidAppBundlePath to ocidAppBundlePathStr's stringByStandardizingPath
####アプリケーションのパスをURLに
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidAppBundlePath
end tell
end if
########処理分岐(スクリプトメニュー対策)
tell current application
set strName to name as text
end tell
if strName is "osascript" then
set aliasAppPathURL to ocidAppPathURL as alias
set aliasFilePathURL to ocidFilePathURL as alias
tell application "Finder"
open file aliasFilePathURL using aliasAppPathURL
end tell
return "Finderで起動しました"
else
###開くURLを格納用のArrayを作成して
set ocidOpenURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###開くURLをArrayに格納
ocidOpenURLArray's addObject:ocidFilePathURL
####NSWorkspaceの初期化
set objNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
####コンフィグレーション
set ocidOpenConfiguration to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidOpenConfiguration's setHides:(false as boolean)
ocidOpenConfiguration's setRequiresUniversalLinks:(false as boolean)
####開く
objNSWorkspace's openURLs:ocidOpenURLArray withApplicationAtURL:ocidAppPathURL configuration:ocidOpenConfiguration completionHandler:(missing value)
#####
return "NSWorkspaceで起動しました"
end if
end if
| 固定リンク
#!/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 refNSDate : a reference to refMe's NSDate
property refNSCalendar : a reference to refMe's NSCalendar
property refNSTimeZone : a reference to refMe's NSTimeZone
property refNSDateFormatter : a reference to refMe's NSDateFormatter
###日付フォーマットは<http://nsdateformatter.com>参照
set listDateFormat to {"AD yyyyMMdd", "AD yyyy年MM月dd日", "AD yyyy年MM月dd日EEEE", "AD Gyyyy年MM月dd日EEEE", "JE yyMMdd", "JE Gyyyy年MM月dd日", "JE Gyyyy年MM月dd日 EEEE", "MMM.dd,yyyy", "EEEE MMMM dd yyyy"} as list
##############################
#### 選択範囲のテキストを取得
##############################
tell application "CotEditor"
activate
set numCntActvDoc to (count of document) as integer
if numCntActvDoc = 0 then
return "ドキュメントがありません"
end if
tell front document
set strSelectionContents to contents of selection
end tell
end tell
set strChkText to strSelectionContents as text
############################
####ダイアログを出す
############################
try
tell current application
activate
set listResponse to (choose from list listDateFormat with title "選んでください" with prompt "日付フォーマット" default items (item 1 of listDateFormat) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
end tell
on error
log "エラーしました"
return "エラーしました"
error "エラーしました" number -200
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
error "キャンセルしました" number -200
end if
############################
####戻り値が複数選択の本処理
############################
###ペーストボードに戻すテキストの初期化
set strOutPutText to "" as text
###繰り返し
repeat with itemResponse in listResponse
####テキストで確定
set strResponse to itemResponse as text
####戻り値の最初がADから始まる場合は
if strResponse starts with "AD" then
set strDateFormat to doReplace(strResponse, "AD ", "")
####英語モード書式での日付を取得
set strDateText to doGetDateNo(strDateFormat) as text
else if strResponse starts with "JE" then
####戻り値の最初がJEから始まる場合は
set strDateFormat to doReplace(strResponse, "JE ", "")
####日本語モード書式での日付を取得
set strDateText to doGetDateNoJP(strDateFormat) as text
else
###無印は英語モード
set strDateText to doGetDateNo(strResponse) as text
end if
####戻り値
set strOutPutText to strDateText & "" as text
end repeat
############################
####日本語書式
############################
if strChkText is "" then
tell application "CotEditor"
tell front document
properties
set contents of selection to strOutPutText
end tell
end tell
else
tell application "CotEditor"
tell front document
properties
set contents of selection to strOutPutText & strSelectionContents
end tell
end tell
end if
############################
####日本語書式
############################
to doGetDateNoJP(strDateFormat)
####日付情報の取得
set ocidDate to refNSDate's |date|()
###日付のフォーマットを定義
set ocidNSDateFormatter to refNSDateFormatter's alloc()'s init()
set ocidJPCalendar to refNSCalendar's alloc()'s initWithCalendarIdentifier:(refMe's NSCalendarIdentifierJapanese)
set ocidNStimezoneJP to refNSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:ocidNStimezoneJP
ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP")
ocidNSDateFormatter's setCalendar:ocidJPCalendar
ocidNSDateFormatter's setDateFormat:strDateFormat
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNoJP
############################
####英語書式
############################
to doGetDateNo(strDateFormat)
####日付情報の取得
set ocidDate to refNSDate's |date|()
###日付のフォーマットを定義
set ocidNSDateFormatter to refNSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"en_US")
ocidNSDateFormatter's setDateFormat:strDateFormat
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo
############################
####文字の置換
############################
to doReplace(argOrignalText, argSearchText, argReplaceText)
set ocidOrignalText to refMe's NSString's stringWithString:argOrignalText
set ocidReplasetText to ocidOrignalText's stringByReplacingOccurrencesOfString:argSearchText withString:argReplaceText
set strReplasetText to ocidReplasetText as text
return strReplasetText
end doReplace
| 固定リンク
#!/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
####設定項目
##UTI
set strUTI to "com.apple.Safari" as text
###APP名
set strAppName to "Safari" as text
#############################
####前面書類のファイルパスを取得
#############################
tell application "CotEditor"
set numCntActvDoc to (count of document) as integer
if numCntActvDoc = 0 then
return "ドキュメントがありません"
end if
tell front document
log "処理開始"
end tell
set aliasFilePath to (file of front document) as alias
end tell
set strFilePath to POSIX path of aliasFilePath as text
#####パスのString
set ocidFilePathStr to (refMe's NSString's stringWithString:strFilePath)
#####パスにして
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
###URLに
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath
#####拡張子を取得
set ocidExtensionName to ocidFilePath's pathExtension()
#####小文字にして
set ocidExtensionNameLC to ocidExtensionName's lowercaseString()
####テキストで確定しておく
set strExtensionName to ocidExtensionNameLC as text
#############################
####本処理
#############################
####拡張子がHTMLなら
if strExtensionName is "html" then
####UTIからアプリケーションのパスを求める
set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:strUTI
if ocidAppBundle is (missing value) then
####この方法は予備
set aliasAppPath to path to application strAppName as alias
set strAppBundlePath to POSIX path of aliasAppPath as text
set ocidAppBundlePath to (refMe's NSString's stringWithString:strAppBundlePath)
else
set ocidAppBundlePath to ocidAppBundle's bundlePath()
end if
####アプリケーションのパスをURLに
set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidAppBundlePath
log ocidAppPathURL's |path| as text
###開くURLを格納用のArrayを作成して
set ocidOpenURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
###開くURLをArrayに格納
ocidOpenURLArray's addObject:ocidFilePathURL
####NSWorkspaceの初期化
set objNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
####コンフィグレーション
set ocidOpenConfiguration to refMe's NSWorkspaceOpenConfiguration's configuration()
ocidOpenConfiguration's setHides:(false as boolean)
ocidOpenConfiguration's setRequiresUniversalLinks:(false as boolean)
####開く
objNSWorkspace's openURLs:ocidOpenURLArray withApplicationAtURL:ocidAppPathURL configuration:ocidOpenConfiguration completionHandler:(missing value)
end if
| 固定リンク
| 固定リンク
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