AppleScript NSPasteboard

ペーストボードの内容(テキスト)にBRを入れて戻す


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use scripting additions

property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

########################
## クリップボードの中身取り出し
###初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strReadString to (the clipboard as text) as text
  end tell
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strReadString to ocidReadString as text
  end if
end if
########################
#
set ocidReadString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
set ocidSetValue to refMe's NSString's stringWithString:(strReadString)
ocidReadString's setString:(ocidSetValue)
############################
#改行コード判定
set ocidCrRange to (ocidReadString's rangeOfString:("\r"))'s location()
set ocidLfRange to (ocidReadString's rangeOfString:("\n"))'s location()
if ocidCrRange = refNSNotFound then
log "Mac改行は無い"
  if ocidLfRange = refNSNotFound then
log "Mac改行もUNIX改行は無い=改行の無い1行か空のテキスト"
    set ocidLength to ocidReadString's |length|
    if ocidLength = (refMe's NSNumber's numberWithInteger:0) then
log "空のテキスト UNIX改行をセットします"
      set ocidNewLineChar to (refMe's NSString's stringWithString:("\n"))
    else
log "改行無しの1行テキスト UNIX改行をセットします"
      set ocidNewLineChar to (refMe's NSString's stringWithString:("\n"))
    end if
  else
log "Mac改行無+UNIX改行あり=UNIX改行"
    set ocidNewLineChar to (refMe's NSString's stringWithString:("\n"))
  end if
else
  if ocidLfRange = refNSNotFound then
log "MacがあるUNIX改行は無い=Mac改行"
    set ocidNewLineChar to (refMe's NSString's stringWithString:("\r"))
  else
log "Mac改行ある+UNIX改行あり=Windows改行"
    set ocidNewLineChar to (refMe's NSString's stringWithString:("\r\n"))
  end if
end if
#改行毎でリストにする
set ocidLineArray to (ocidReadString's componentsSeparatedByString:(ocidNewLineChar))
############################
#戻し用のテキスト
set ocidSaveString to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
#
repeat with itemArray in ocidLineArray
  #行テキスト
(ocidSaveString's appendString:(itemArray))
  #<BR />
  set ocidSetValue to (refMe's NSString's stringWithString:("<BR />"))
(ocidSaveString's appendString:(ocidSetValue))
  #改行
(ocidSaveString's appendString:(ocidNewLineChar))
end repeat

set strSaveString to ocidSaveString as text



###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
###ICON
tell application "Finder"
  set aliasIconPath to (POSIX file "/System/Applications/TextEdit.app/Contents/Resources/AppIcon.icns") as alias
end tell
set strTitle to ("戻り値です") as text
set strMes to ("<BR />入れました") as text
set recordResult to (display dialog strMes with title strTitle default answer strSaveString buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
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
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
################################
#レコード
set recordUTI2Type to {|com.apple.webarchive|:("com.apple.webarchive"), |public.png|:(refMe's NSPasteboardTypePNG), |public.url|:(refMe's NSPasteboardTypeURL), |public.tiff|:("public.tiff"), |public.rtf|:(refMe's NSPasteboardTypeRTF), |com.adobe.pdf|:(refMe's NSPasteboardTypePDF), |public.utf8-plain-text|:(refMe's NSPasteboardTypeString), |public.tab-separated-values-text|:(refMe's NSPasteboardTypeTabularText), |public.file-url|:(refMe's NSPasteboardTypeFileURL), |public.html|:(refMe's NSPasteboardTypeHTML), |com.apple.icns|:("com.apple.icns")} as record
set ocidUTI2TypeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidUTI2TypeDict's setDictionary:(recordUTI2Type)
#
set recordUTI2Class to {|com.apple.webarchive|:(refMe's NSData), |public.png|:(refMe's NSData), |com.apple.icns|:(refMe's NSData), |public.tiff|:(refMe's NSData), |public.rtf|:(refMe's NSData), |com.adobe.pdf|:(refMe's NSData), |public.utf8-plain-text|:(refMe's NSString), |public.tab-separated-values-text|:(refMe's NSString), |public.url|:(refMe's NSURL), |public.file-url|:(refMe's NSURL), |public.html|:(refMe's NSString)} as record
set ocidUTI2ClassDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidUTI2ClassDict's setDictionary:(recordUTI2Class)
#
set recordUTI2Extension to {|com.apple.webarchive|:("webarchive"), |com.apple.icns|:"icns", |public.png|:"png", |public.tiff|:"tif", |public.rtf|:"rtf", |com.adobe.pdf|:"pdf", |public.utf8-plain-text|:"txt", |public.tab-separated-values-text|:"tsv", |public.url|:"webloc", |public.file-url|:"fileloc", |public.html|:"html"} as record
set ocidUTI2ExtensionDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidUTI2ExtensionDict's setDictionary:(recordUTI2Extension)
#
set ocidAllKeysArray to ocidUTI2ExtensionDict's allKeys()
#set listAllKeysArray to ocidAllKeysArray as list
################################
###ペーストボードを取得
set appNSPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to appNSPasteboard's types()
log ocidPastBoardTypeArray as list
#ペーストボードのデータタイプのみ処理するための処理
set ocidPasteboardClassArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
repeat with itemArray in ocidPastBoardTypeArray
  set boolContain to (ocidAllKeysArray's containsObject:(itemArray))
  if boolContain is true then
(ocidPasteboardClassArray's addObject:(itemArray))
  end if
end repeat
set listAllKeysArray to ocidPasteboardClassArray as list

##############################
###ダイアログを前面に出す
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strTitle to "選んでください" as text
set strPrompt to "複数選択時はコマンドキーをおしながら" as text
try
  set listResponse to (choose from list listAllKeysArray with title strTitle with prompt strPrompt default items (item 1 of listAllKeysArray) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
  error "エラーしました" number -200
end try
if listResponse = {} then
log "何も選択していない"
  # 止めるなら ここに returnを入れる
else if (item 1 of listResponse) is false then
return "キャンセルしました"
  error "キャンセルしました" number -200
else
  ##############################
  ###データの保存先
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDocumentDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidDocumentDirPathURL to ocidURLsArray's firstObject()
  #
  set strSetValue to doGetDateNo("yyyyMMdd_HHmmss") as text
  set strSetValue to ("SavePasteboard/" & strSetValue) as text
  set ocidSaveDirPathURL to ocidDocumentDirPathURL's URLByAppendingPathComponent:(strSetValue)
  #
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  # 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set aliasSaveDirPath to (ocidSaveDirPathURL's absoluteURL()) as alias
  ######
  repeat with itemResponse in listResponse
    set strUTI to itemResponse as text
    set ocidClass to (ocidUTI2TypeDict's objectForKey:(strUTI))
    set ocidClassesArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
(ocidClassesArray's addObject:(ocidClass))
    set ocidReadData to (appNSPasteboard's dataForType:(ocidClass))
log className() of ocidReadData as text
    set strExtension to (ocidUTI2ExtensionDict's valueForKey:(strUTI)) as text
    set strSaveFileName to (strUTI & "." & strExtension) as text
log strUTI
log strExtension
    set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName))
    
    if strUTI contains "url" then
      set ocidClass to (ocidUTI2ClassDict's objectForKey:(strUTI))'s class
      set ocidClassArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
(ocidClassArray's addObject:(ocidClass))
      set ocidReadDataArray to (appNSPasteboard's readObjectsForClasses:(ocidClassArray) options:(missing value))
      set ocidURL to ocidReadDataArray's firstObject()
      set strURL to (ocidURL's absoluteString()) as text
      set ocidPlistDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPlistDict's setValue:(strURL) forKey:("URL"))
      set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
      set listPlistEditDataArray to (refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0 |error|:(reference))
      set ocidPlistData to item 1 of listPlistEditDataArray
log doSaveData(ocidPlistData, ocidSaveFilePathURL)
    else
      
      # log doSaveData(ocidReadData, ocidSaveFilePathURL)
      # else if strUTI is "public.png" then
      # log doSaveData(ocidReadData, ocidSaveFilePathURL)
      # else if strUTI is "com.adobe.pdf" then
      # log doSaveData(ocidReadData, ocidSaveFilePathURL)
      # else if strUTI is "public.rtf" then
      # log doSaveData(ocidReadData, ocidSaveFilePathURL)
      # else if strUTI is "public.html" then
      # log doSaveData(ocidReadData, ocidSaveFilePathURL)
      # else if strUTI is "public.tab-separated-values-text" then
      # log doSaveData(ocidReadData, ocidSaveFilePathURL)
      # else if strUTI is "public.utf8-plain-text" then
log doSaveData(ocidReadData, ocidSaveFilePathURL)
      
    end if
    
  end repeat
end if
tell application "Finder"
open location aliasSaveDirPath
end tell


return


########################
#データの保存
on doSaveData(argData, argSaveFilePathURL)
  #保存
  set ocidOption to (refMe's NSDataWritingAtomic)
  set listDone to argData's writeToURL:(argSaveFilePathURL) options:(ocidOption) |error|:(reference)
  if (item 1 of listDone) is false then
log "保存に失敗しました"
return false
  else
return true
  end if
end doSaveData


##############################
### 今の日付日間 テキスト
to doGetDateNo(argDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
ocidNSDateFormatter's setDateFormat:(argDateFormat)
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo



return


|

[Stickies]クリップボードからステッキーズを生成する(仮)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# 
#com.cocolog-nifty.quicktimer.icefloe
# 新規でステッキーズを生成します 色や文言はカスタマイズして利用してください
(*
v2 ZOrderの値を修正した


*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()
#
tell application id "com.apple.Stickies"
quit
end tell
#
################################
######ペーストボードを取得
################################
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####タイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types()
log ocidPastBoardTypeArray as list
set boolContainPng to ocidPastBoardTypeArray's containsObject:"public.png"
set boolContainText to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
set boolContainRtf to ocidPastBoardTypeArray's containsObject:"public.rtf"
set boolContainTiff to ocidPastBoardTypeArray's containsObject:"public.tiff"

########################
##
########################
#保存先ディレクトリ
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
set ocidSaveDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Containers/com.apple.Stickies/Data/Library/Stickies") isDirectory:(true)
###処理の分岐
if boolContainRtf is true then
  ##RTFの場合はそのまま
  set ocidAttarStringArray to ocidPasteboard's readObjectsForClasses:({refMe's NSAttributedString}) options:(missing value)
  set ocidAttarString to ocidAttarStringArray's firstObject()
  set ocidRange to refMe's NSMakeRange(0, (ocidAttarString's |length|))
  set ocidAttarData to ocidAttarString's RTFFromRange:(ocidRange) documentAttributes:(missing value)
  set ocidUUIDString to doSaveAttarData(ocidAttarData, ocidSaveDirPathURL)
  
else if boolContainText is true then
  ##テキストの場合はダイアログを出す
  set strReadString to doGetPasteboard()
  set aliasIconPath to doGetAppIconAliasFilePath("com.apple.Stickies")
  #前面に
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set strTitle to ("入力してください") as text
  set strMes to ("メッセージ") as text
  set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 30 with icon aliasIconPath without hidden answer)
  if (gave up of recordResult) is true then
return "時間切れです"
  else if (button returned of recordResult) is "キャンセル" then
return "キャンセルです"
  else
    set strSetValue to (text returned of recordResult) as text
  end if
  ####
  set ocidAttarData to doMakeAttarText(strSetValue)
  set ocidUUIDString to doSaveAttarData(ocidAttarData, ocidSaveDirPathURL)
  
else if boolContainPng is true then
  ##画像の場合
  set strSaveImageFileName to ("Attach.png") as text
  set ocidImageData to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
  set ocidUUIDString to doSaveImageAttarData(ocidImageData, ocidSaveDirPathURL, strSaveImageFileName)
  
else if boolContainTiff is true then
  set strSaveImageFileName to ("Attach.tif") as text
  set ocidImageData to ocidPasteboard's dataForType:(refMe's NSPasteboardTypeTIFF)
  set ocidUUIDString to doSaveImageAttarData(ocidImageData, ocidSaveDirPathURL, strSaveImageFileName)
else
return "キャンセル"
end if



################################

#PLIST 設定ファイルの読み込み
set ocidPlistFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(".SavedStickiesState") isDirectory:(false)
set ocidPlistArray to refMe's NSMutableArray's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)
set numCntArray to (count of ocidPlistArray) as integer
#追加するDICT=新しいステっキーズのデータ
set ocidAddDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
#数値系 前後関係のINDEX
set numSetValue to (numCntArray + 1) as integer
ocidAddDict's setValue:(numSetValue) forKey:("ZOrder")
#開いているのが1 閉じているのが0
set numSetValue to (0) as integer
ocidAddDict's setValue:(numSetValue) forKey:("ExpandFrameY")
#日本語スペルチェックは無いのでデフォルト値
set numSetValue to (8455) as integer
ocidAddDict's setValue:(numSetValue) forKey:("SpellCheckingTypes")
#テキスト系
ocidAddDict's setValue:(ocidUUIDString) forKey:("UUID")
#開いた時のサイズ
ocidAddDict's setValue:("{300, 200}") forKey:("ExpandedSize")
#ポジション 左上原点 xy wh
ocidAddDict's setValue:("{{30, 335}, {300, 200}}") forKey:("Frame")
#BOOL系
set ocidBool to (refMe's NSNumber's numberWithBool:false)
ocidAddDict's setValue:(ocidBool) forKey:("Translucent")
set ocidBool to (refMe's NSNumber's numberWithBool:true)
ocidAddDict's setValue:(ocidBool) forKey:("Floating")
#色データはテキスト形式のDICTを個別で作成 
#ControlColor
set ocidSetObjectDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set numSetValue to (0.859) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Red")
set numSetValue to (0.772) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Green")
set numSetValue to (0.012) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Blue")
set numSetValue to (1) as integer
ocidSetObjectDict's setValue:(numSetValue) forKey:("Alpha")
ocidAddDict's setObject:(ocidSetObjectDict) forKey:("ControlColor")
#HighlightColor
set ocidSetObjectDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set numSetValue to (0.737) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Red")
set numSetValue to (0.662) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Green")
set numSetValue to (0.007) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Blue")
set numSetValue to (1) as integer
ocidSetObjectDict's setValue:(numSetValue) forKey:("Alpha")
ocidAddDict's setObject:(ocidSetObjectDict) forKey:("HighlightColor")
#SpineColor
set ocidSetObjectDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set numSetValue to (0.997) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Red")
set numSetValue to (0.917) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Green")
set numSetValue to (0.239) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Blue")
set numSetValue to (1) as integer
ocidSetObjectDict's setValue:(numSetValue) forKey:("Alpha")
ocidAddDict's setObject:(ocidSetObjectDict) forKey:("SpineColor")
#StickyColor
set ocidSetObjectDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set numSetValue to (0.996) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Red")
set numSetValue to (0.956) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Green")
set numSetValue to (0.611) as number
ocidSetObjectDict's setValue:(numSetValue) forKey:("Blue")
set numSetValue to (1) as integer
ocidSetObjectDict's setValue:(numSetValue) forKey:("Alpha")
ocidAddDict's setObject:(ocidSetObjectDict) forKey:("StickyColor")
#作成した設定を読み込んだPLITに追加
ocidPlistArray's addObject:(ocidAddDict)
#SavedStickiesStateはテキスト形式のXMLなのでXML形式で保存
set ocidNSbplist to refMe's NSPropertyListXMLFormat_v1_0
set listPlistData to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistArray) format:ocidNSbplist options:0 |error|:(reference)
set ocidPlistEditData to (item 1 of listPlistData)
###この場合は上書き
set listDone to ocidPlistEditData's writeToURL:(ocidPlistFilePathURL) options:0 |error|:(reference)
if (item 1 of listDone) is false then
return "保存に失敗しました"
end if

delay 0.5
tell application id "com.apple.Stickies"
activate
end tell


########################
## イメージの保存とRTFの生成
########################
on doSaveImageAttarData(argImageData, argSaveDirPathURL, argSaveImageFileName)
  
  ##RTFを生成
  set strRTFString to ("{\\rtf1\\ansi\\ansicpg932\\cocoartf2761{\\NeXTGraphic Attach.png \\appleattachmentpadding0}}") as text
  set ocidRTFString to refMe's NSString's stringWithString:(strRTFString)
  set ocidAttarData to ocidRTFString's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
  #UUID=rtfdファイル名=ディレクトリ名
  set ocidConcreteUUID to refMe's NSUUID's UUID()
  set ocidUUIDString to ocidConcreteUUID's UUIDString()
  #ファイル名は固定
  set strFileName to ("TXT.rtf") as text
  #rtfdファイル=ディレクトリのURL
  set ocidUUIDDirPathURL to argSaveDirPathURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(false)
  set ocidRtfdDirPathURL to ocidUUIDDirPathURL's URLByAppendingPathExtension:("rtfd")
  #ディレクトリを作る アクセス権755
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set appFileManager to refMe's NSFileManager's defaultManager()
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidRtfdDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #RTFデータの保存先
  set ocidSaveRTFPathURL to ocidRtfdDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false)
  #イメージデータの保存先
  set ocidSaveImagePathURL to ocidRtfdDirPathURL's URLByAppendingPathComponent:(argSaveImageFileName) isDirectory:(false)
  #保存
  set ocidOption to (refMe's NSDataWritingAtomic)
  #RTF
  set listDone to ocidAttarData's writeToURL:(ocidSaveRTFPathURL) options:(ocidOption) |error|:(reference)
  if (item 1 of listDone) is false then
return "保存に失敗しました"
  end if
  #イメージファイル
  set listDone to argImageData's writeToURL:(ocidSaveImagePathURL) options:(ocidOption) |error|:(reference)
  if (item 1 of listDone) is false then
return "保存に失敗しました"
  end if
return ocidUUIDString
end doSaveImageAttarData

########################
## Attarテキストの保存
########################
on doSaveAttarData(argAttarData, argSaveDirPathURL)
  #UUID=rtfdファイル名=ディレクトリ名
  set ocidConcreteUUID to refMe's NSUUID's UUID()
  set ocidUUIDString to ocidConcreteUUID's UUIDString()
  #ファイル名は固定
  set strFileName to ("TXT.rtf") as text
  
  #rtfdファイル=ディレクトリのURL
  set ocidUUIDDirPathURL to argSaveDirPathURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(false)
  set ocidRtfdDirPathURL to ocidUUIDDirPathURL's URLByAppendingPathExtension:("rtfd")
  #ディレクトリを作る アクセス権755
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
  set appFileManager to refMe's NSFileManager's defaultManager()
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidRtfdDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #RTFデータの保存先
  set ocidSaveRTFPathURL to ocidRtfdDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:(false)
  #アトリビュートテキストのDATAを保存
  set ocidOption to (refMe's NSDataWritingAtomic)
  set listDone to argAttarData's writeToURL:(ocidSaveRTFPathURL) options:(ocidOption) |error|:(reference)
  if (item 1 of listDone) is false then
return "保存に失敗しました"
  end if
return ocidUUIDString
end doSaveAttarData

########################
## RTFデータの作成
########################
on doMakeAttarText(argText)
  #アトリビュートテキストを生成する
  set ocidAttarString to refMe's NSMutableAttributedString's alloc()'s initWithString:(argText)
  #セットするDICT
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  #フォントサイズ
  #フォントファミリー指定はスタイル入りで
  set ocidFont to refMe's NSFont's fontWithName:("BIZ UDPGothic Bold") |size|:(18)
  #システムフォント指定
  #set ocidFont to refMe's NSFont's boldSystemFontOfSize:(18)
ocidAttrDict's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName)
  #色指定
  #set ocidSetColor to refMe's NSColor's colorWithDisplayP3Red:1.0 green:0 blue:0 alpha:1.0
  #set ocidSetColor to refMe's NSColor's colorWithCalibratedRed:0.044 green:0.378 blue:0.673 alpha:1.0
  set ocidSetColor to refMe's NSColor's grayColor()
ocidAttrDict's setObject:(ocidSetColor) forKey:(refMe's NSForegroundColorAttributeName)
  #
  set ocidRange to refMe's NSMakeRange(0, (ocidAttarString's |length|))
ocidAttarString's addAttributes:(ocidAttrDict) range:(ocidRange)
  
  set ocidAttarData to ocidAttarString's RTFFromRange:(ocidRange) documentAttributes:(missing value)
return ocidAttarData
end doMakeAttarText
########################
## クリップボードの中身取り出し
########################
on doGetPasteboard()
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidPastBoardTypeArray to appPasteboard's types
  ###テキストがあれば
  set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
  if boolContain = true then
    ###値を格納する
    tell application "Finder"
      set strReadString to (the clipboard as text) as text
    end tell
    ###Finderでエラーしたら
  else
    set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
    if boolContain = true then
      set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
      set strReadString to ocidReadString as text
    else
log "テキストなし"
      set strReadString to "入力してください" as text
    end if
  end if
return strReadString
end doGetPasteboard


########################
#AppIconのパスを求める
########################
on doGetAppIconAliasFilePath(argBundleID)
  #
  set appFileManager to refMe's NSFileManager's defaultManager()
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(argBundleID))
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
  end if
  if ocidAppBundle ≠ (missing value) then
    set ocidAppPathURL to ocidAppBundle's bundleURL()
  else if ocidAppBundle = (missing value) then
    set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
  end if
  if ocidAppPathURL = (missing value) then
    tell application "Finder"
      try
        set aliasAppApth to (application file id strBundleID) as alias
      on error
return "アプリケーションが見つかりませんでした"
      end try
    end tell
    set strAppPath to POSIX path of aliasAppApth as text
    set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
    set strAppPath to strAppPathStr's stringByStandardizingPath()
    set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:true
  end if
  ####ダイアログに指定アプリのアイコンを表示する
  ###アイコン名をPLISTから取得
  set ocidPlistPathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist") isDirectory:false
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
  set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
  ###ICONのURLにして
  set strPath to ("Contents/Resources/" & strIconFileName) as text
  set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
  ###拡張子の有無チェック
  set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
  if strExtensionName is "" then
    set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
  end if
  ##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
  ###ICONファイルが実際にあるか?チェック
  set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
  ###ICONがみつかない時用にデフォルトを用意する
  if boolExists is false then
    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
  else
    set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
  end if
return aliasIconPath
end doGetAppIconAliasFilePath


|

[NSPasteboard]ファイルパス ファイルURL

ファイルURL

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


########################
## クリップボードの中身取り出し
########################
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
##中身の要素
set ocidPastBoardTypeArray to ocidPasteboard's types
##NSURL
set boolContain to ocidPastBoardTypeArray's containsObject:("public.file-url")
if boolContain is true then
  set ocidClassesArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidClassesArrayM's addObject:(refMe's NSURL)
  set ocidFilePathURLArray to ocidPasteboard's readObjectsForClasses:(ocidClassesArrayM) options:(missing value)
else if boolContain is false then
  set boolContain to ocidPastBoardTypeArray's containsObject:("NSFilenamesPboardType")
  if boolContain is true then
    set ocidFilePathArray to ocidPasteboard's propertyListForType:(refMe's NSFilenamesPboardType)
    set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
    repeat with itemArray in ocidFilePathArray
      set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(itemArray))
(ocidFilePathURLArray's addObject:(ocidFilePathURL))
    end repeat
  else
    set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
return "ファイルのパスの取得に失敗しました"
  end if
end if
log ocidFilePathURLArray as list

ファイルパス

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


########################
## クリップボードの中身取り出し
########################
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
##中身の要素
set ocidPastBoardTypeArray to ocidPasteboard's types
#
set boolContain to ocidPastBoardTypeArray's containsObject:("NSFilenamesPboardType")
if boolContain is true then
  set ocidFilePathArray to ocidPasteboard's propertyListForType:(refMe's NSFilenamesPboardType)
  
else if boolContain is false then
  set boolContain to ocidPastBoardTypeArray's containsObject:("public.file-url")
  if boolContain is true then
    set ocidClassesArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidClassesArrayM's addObject:(refMe's NSURL)
    set ocidFilePathURLArray to ocidPasteboard's readObjectsForClasses:(ocidClassesArrayM) options:(missing value)
    set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
    repeat with itemArray in ocidFilePathURLArray
      set ocidFilePath to itemArray's |path|
(ocidFilePathArray's addObject:(ocidFilePath))
    end repeat
    
    
  end if
else
  set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
return "ファイルのパスの取得に失敗しました"
end if
log ocidFilePathArray as list


|

[NSPasteboard]テキストで取得


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#APIキーは
# https://developer.adobe.com/console/projects
#から取得
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


log doGetPasteboard("")

###########################
(* クリップボードテキスト取出
doGetPasteboard("SOME-TEXT")
SOME-TEXTは
クリップボードにテキストがなかった場合に
戻り値を指定
*)
###########################
to doGetPasteboard(argDefaultText)
  ###渡された値が無い場合
  if argDefaultText = (missing value) then
    set strMesText to "" as text
  else
    set strMesText to argDefaultText as text
  end if
  ## クリップボードの中身取り出し
  set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidPastBoardTypeArray to ocidPasteboard's types
  ###テキストがあれば
  set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
  if boolContain = true then
    set strPasteboardString to (ocidPasteboard's stringForType:"public.utf8-plain-text") as text
  else
    set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
    if boolContain = true then
      set ocidPasteboardString to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
      set strPasteboardString to ocidPasteboardString as text
    else
      ###取得できなかった場合はメッセージを返す
      set strPasteboardString to (strMesText) as text
    end if
  end if
return strPasteboardString
end doGetPasteboard


|

クリップボードの内容に『com.apple.icns』があればアイコンなら保存


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

################################
##### パス関連
################################
###ファイル名用に時間を取得する
set strDateno to doGetDateNo("yyyyMMddhhmmss") as text
###保存先
set strFilePath to "~/Desktop/Icons-" & strDateno & ".icns" as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false

################################
######ペーストボードを取得
################################
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####タイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types()
log ocidPastBoardTypeArray as list
#####イメージがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"com.apple.icns"
if boolContain is true then
  set ocidIconData to ocidPasteboard's dataForType:("com.apple.icns")
else
return "イメージ以外なので中止"
end if
################################
#####NSimageにして
################################
set ocidImageData to refMe's NSImage's alloc()'s initWithData:(ocidIconData)
set ocidTffRep to ocidImageData's TIFFRepresentation
################################
##### 保存
################################
#####
## set boolFileWrite to (ocidTiffData's writeToURL:ocidFilePathURL atomically:true)
#####保存(PNG変換等も考えて今回はNSImage経由にしてみた)
set boolFileWrite to (ocidTffRep's writeToURL:(ocidFilePathURL) atomically:true)

################################
##### ファイル名用の時間
################################
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

ペーストボード内の文字数


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use scripting additions

property refMe : a reference to current application

##ペーストボード初期化
set appPasteboard to refMe's NSPasteboard's generalPasteboard()
##この方法だとスクリプトメニューから実行した時エラーになる
## set ocidStringData to appPasteboard's stringForType:(refMe's NSPasteboardTypeString)
##ペーストボードからテキストを取り出す
set ocidStringData to appPasteboard's stringForType:("public.utf8-plain-text")
set ocidText to (refMe's NSString's stringWithString:(ocidStringData))
##文字数数える
set numCntText to ocidText's |length|() as integer

###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
###ICON
tell application "Finder"
  set aliasIconPath to (POSIX file "/System/Applications/TextEdit.app/Contents/Resources/AppIcon.icns") as alias
end tell

set strMes to ("文字数:" & numCntText) as text
set recordResult to (display dialog strMes with title strMes default answer numCntText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "クリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
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
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

################################
##### パス関連
################################
##ベースファイル名
set strBaseFileName to "クリップボード" as text
##デスクトップ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()

################################
######ペーストボードを取得
################################
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####タイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types()
###タイプをリストに
set listType to {} as list
repeat with itemPastBoardTypeArray in ocidPastBoardTypeArray
  set strPastBoardTypeArray to (itemPastBoardTypeArray) as text
  if strPastBoardTypeArray is "public.utf16-external-plain-text" then
    log "UTF16はスキップ"
  else if strPastBoardTypeArray contains "public" then
    set end of listType to strPastBoardTypeArray
  end if
end repeat
if listType = {} then
return "書き出し出来ない"
end if
################################
######ペーストボードを取得
################################
###ダイアログを前面に出す
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
try
  set listResponse to (choose from list listType with title "選んでください" with prompt "フォーマットを選んでください" default items (item 1 of listType) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strResponse to (item 1 of listResponse) as text
################################
##### 本処理
################################
if strResponse is "public.tiff" then
  set strBaseFileName to strBaseFileName & "TIFF"
  set ocidSaveData to ocidPasteboard's dataForType:(refMe's NSPasteboardTypeTIFF)
  set strExtension to "tiff"
  set strFileName to (strBaseFileName & "." & strExtension) as text
  set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)
  set boolTextEdit to false as boolean
else if strResponse is "public.png" then
  set strBaseFileName to strBaseFileName & "PNG"
  set ocidSaveData to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
  set strExtension to "png"
  set strFileName to (strBaseFileName & "." & strExtension) as text
  set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)
  set boolTextEdit to false as boolean
else if strResponse is "public.rtf" then
  set strBaseFileName to strBaseFileName & "RTF"
  set ocidSaveData to ocidPasteboard's dataForType:(refMe's NSPasteboardTypeRTF)
  set strExtension to "rtf"
  set strFileName to (strBaseFileName & "." & strExtension) as text
  set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)
  set boolTextEdit to true as boolean
else if strResponse is "public.html" then
  set strBaseFileName to strBaseFileName & "HTML"
  set ocidSaveData to ocidPasteboard's dataForType:(refMe's NSPasteboardTypeHTML)
  set strExtension to "html"
  set strFileName to (strBaseFileName & "." & strExtension) as text
  set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)
  set boolTextEdit to true as boolean
else if strResponse is "public.utf8-plain-text" then
  set strBaseFileName to strBaseFileName & "TEXT"
  set ocidSaveData to ocidPasteboard's dataForType:(refMe's NSPasteboardTypeString)
  set strExtension to "txt"
  set strFileName to (strBaseFileName & "." & strExtension) as text
  set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)
  set boolTextEdit to true as boolean
else
return "この処理では処理しない"
end if
set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
###ファイルの有無チェック
set boolDirExists to appFileManager's fileExistsAtPath:(ocidSaveFilePath) isDirectory:(false)
###すでに同名がある場合は日付時間連番を付与
if boolDirExists is true then
  set strDateNo to doGetDateNo("yyyyMMddhhmmss")
  set strFileName to (strBaseFileName & "." & strDateNo & "." & strExtension) as text
  set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
end if

################################
##### 保存
################################
####ファイルに書き出し
set boolFileWrite to (ocidSaveData's writeToURL:(ocidSaveFilePathURL) atomically:true)
################################
##### open
################################
set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
if boolTextEdit is true then
  tell application "TextEdit"
    activate
    open file aliasSaveFilePath
  end tell
else
  tell application id "com.apple.Preview"
    activate
    open file aliasSaveFilePath
  end tell
end if
################################
##### 日付
################################
to doGetDateNo(strDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo


|

[readObjectsForClasses]可変テキストで受け取る


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
###NSPasteboardはAppkitなので必須
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

################################
######ペーストボードテキスト取得
################################
##初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
##可変テキストとして受け取る
set ocidPasteboardArray to ocidPasteboard's readObjectsForClasses:({refMe's NSMutableString}) options:(missing value)
##シングルARRAYが空ならペーストボードの中身が画像とか他のものなので初期値を作る
if (count of ocidPasteboardArray) = 0 then
  ###初期値
  set ocidPasteboardStrings to 7200 as text
else
  ###ペーストボードの中身をテキストで確定
  set strPasteboardStrings to (ocidPasteboardArray's objectAtIndex:0) as text
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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータタイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types
log ocidPastBoardTypeArray as list
if (ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text") is true then
  set ocidPublicText to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
else
return "テキストを取得出来ません"
end if
##########################################
###変換処理
##########################################
###
set ocidText to (refMe's NSString's stringWithString:ocidPublicText)
set ocidCapitalizedCase to ocidText's capitalizedString()

set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidResponseHalfwidth to (ocidCapitalizedCase's stringByApplyingTransform:ocidNSStringTransform |reverse|:true)
set strResponseHalfwidth to ocidResponseHalfwidth as text
##########################################
###ペーストボードに戻す
##########################################
ocidPasteboard's clearContents()
ocidPasteboard's setString:(strResponseHalfwidth) forType:(refMe's NSPasteboardTypeString)


全角化

【スクリプトエディタで開く】|

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータタイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types
log ocidPastBoardTypeArray as list
if (ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text") is true then
  set ocidPublicText to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
else
return "テキストを取得出来ません"
end if
##########################################
###変換処理
##########################################
###
set ocidText to (refMe's NSString's stringWithString:ocidPublicText)
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidResponseHalfwidth to (ocidText's stringByApplyingTransform:ocidNSStringTransform |reverse|:true)
set strResponseHalfwidth to ocidResponseHalfwidth as text
##########################################
###ペーストボードに戻す
##########################################
ocidPasteboard's clearContents()
ocidPasteboard's setString:(strResponseHalfwidth) forType:(refMe's NSPasteboardTypeString)


半角キャピタライズ

【スクリプトエディタで開く】|

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータタイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types
log ocidPastBoardTypeArray as list
if (ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text") is true then
  set ocidPublicText to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
else
return "テキストを取得出来ません"
end if
##########################################
###変換処理
##########################################
###半角にしてから
set ocidText to (refMe's NSString's stringWithString:ocidPublicText)
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidResponseHalfwidth to (ocidText's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
###小文字にして
set ocidCapitalizedCase to ocidResponseHalfwidth's capitalizedString()
set strCapitalizedCase to ocidCapitalizedCase as text
##########################################
###ペーストボードに戻す
##########################################
ocidPasteboard's clearContents()
ocidPasteboard's setString:(strCapitalizedCase) forType:(refMe's NSPasteboardTypeString)



半角化

【スクリプトエディタで開く】|

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータタイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types
log ocidPastBoardTypeArray as list
if (ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text") is true then
  set ocidPublicText to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
else
return "テキストを取得出来ません"
end if
##########################################
###変換処理
##########################################
###半角にしてから
set ocidText to (refMe's NSString's stringWithString:ocidPublicText)
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidResponseHalfwidth to (ocidText's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
set strResponseHalfwidth to ocidResponseHalfwidth as text
##########################################
###ペーストボードに戻す
##########################################
ocidPasteboard's clearContents()
ocidPasteboard's setString:(strResponseHalfwidth) forType:(refMe's NSPasteboardTypeString)


半角小文字を大文字に

【スクリプトエディタで開く】|

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータタイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types
log ocidPastBoardTypeArray as list
if (ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text") is true then
  set ocidPublicText to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
else
return "テキストを取得出来ません"
end if
##########################################
###変換処理
##########################################
###半角にしてから
set ocidText to (refMe's NSString's stringWithString:ocidPublicText)
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidResponseHalfwidth to (ocidText's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
###小文字にして
set ocidUpperCase to ocidResponseHalfwidth's uppercaseString()
set strUpperCase to ocidUpperCase as text
##########################################
###ペーストボードに戻す
##########################################
ocidPasteboard's clearContents()
ocidPasteboard's setString:(strUpperCase) forType:(refMe's NSPasteboardTypeString)


半角大文字を小文字に

【スクリプトエディタで開く】|

#!/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 framework "AppKit"
use scripting additions

property refMe : a reference to current application

##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータタイプを取得
set ocidPastBoardTypeArray to ocidPasteboard's types
log ocidPastBoardTypeArray as list
if (ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text") is true then
  set ocidPublicText to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
else
return "テキストを取得出来ません"
end if
##########################################
###変換処理
##########################################
###半角にしてから
set ocidText to (refMe's NSString's stringWithString:ocidPublicText)
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidResponseHalfwidth to (ocidText's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
###小文字にして
set ocidLowerCase to ocidResponseHalfwidth's lowercaseString()
set strLowerCase to ocidLowerCase as text
##########################################
###ペーストボードに戻す
##########################################
ocidPasteboard's clearContents()
ocidPasteboard's setString:(strLowerCase) forType:(refMe's NSPasteboardTypeString)



|

その他のカテゴリー

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