AppleScript NSPasteboard

ペーストボードの内容の種類の確認


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use scripting additions
010
011property refMe : a reference to current application
012
013
014################################
015######ペーストボードを取得
016################################
017set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
018####タイプを取得
019set ocidPastBoardTypeArray to ocidPasteboard's types
020#ダイアログに戻すテキスト
021set strOutPutText to ("") as text
022#順番に確認
023repeat with itemType in ocidPastBoardTypeArray
024#タイプをテキストで
025  set strType to itemType as text
026#追加していく
027  set strOutPutText to (strOutPutText & strType & "\n") as text
028end repeat
029
030
031##############################
032#####ダイアログ
033##############################
034tell current application
035  set strName to name as text
036end tell
037if strName is "osascript" then
038  tell application "Finder"
039    activate
040  end tell
041else
042  tell current application
043    activate
044  end tell
045end if
046set strFilePath to ("/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AllMyFiles.icns") as text
047set aliasIconPath to (POSIX file strFilePath) as alias
048try
049  set recordResult to (display dialog "戻り値です" with title "戻り値です" default answer strOutPutText buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
050on error
051  return "エラーしました"
052end try
053if (gave up of recordResult) is true then
054  return "時間切れです"
055end if
056##############################
057#####自分自身を再実行
058##############################
059if button returned of recordResult is "再実行" then
060  tell application "Finder"
061    set aliasPathToMe to (path to me) as alias
062  end tell
063  run script aliasPathToMe with parameters "再実行"
064end if
065##############################
066#####値のコピー
067##############################
068if button returned of recordResult is "クリップボードにコピー" then
069  try
070    set strText to text returned of recordResult as text
071    ####ペーストボード宣言
072    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
073    set ocidText to (refMe's NSString's stringWithString:(strText))
074    appPasteboard's clearContents()
075    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
076  on error
077    tell application "Finder"
078      set the clipboard to strText as text
079    end tell
080  end try
081end if
082
083
084return 0
AppleScriptで生成しました

|

[NSPasteboard]ペーストボードからテキストの取り出し(修正)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#クリップボードに入っているテキストを取り出す
005#
006#
007#com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013
014property refMe : a reference to current application
015
016########################
017## クリップボードの中身取り出し
018#初期化
019set appPasteboard to refMe's NSPasteboard's generalPasteboard()
020#格納されているタイプをリストにして
021set ocidPastBoardTypeArray to appPasteboard's types()
022#テキストがあれば
023set boolContain to ocidPastBoardTypeArray's containsObject:(refMe's NSPasteboardTypeString)
024if (boolContain as boolean) is true then
025  #値を格納する
026  set ocidReadStringData to (appPasteboard's dataForType:(refMe's NSPasteboardTypeString))
027  set ocidReadString to refMe's NSString's alloc()'s initWithData:(ocidReadStringData) encoding:(refMe's NSUTF8StringEncoding)
028else
029    log "テキストなし"
030    return "クリップボードに\nテキストは\nありませんでした"
031    # set strSetSting to ("クリップボードに\nテキストは\nありませんでした") as text
032    # set ocidReadString to refMe's NSMutableString's alloc()'s initWithString:(strSetSting)
033end if
034
035
036
AppleScriptで生成しました

AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#クリップボードに入っているテキストを取り出す
005#
006#
007#com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013
014property refMe : a reference to current application
015
016########################
017## クリップボードの中身取り出し
018#初期化
019set appPasteboard to refMe's NSPasteboard's generalPasteboard()
020#格納されているタイプをリストにして
021set ocidPastBoardTypeArray to appPasteboard's types()
022#テキストがあれば
023set boolContain to ocidPastBoardTypeArray's containsObject:(refMe's NSPasteboardTypeString)
024if (boolContain as boolean) is true then
025  #値を格納する
026    set ocidTypeClassArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
027    ocidTypeClassArray's addObject:(refMe's NSString)
028    set ocidReadStringArray to appPasteboard's readObjectsForClasses:(ocidTypeClassArray) options:(missing value)
029    set ocidReadString to ocidReadStringArray's firstObject()
030else
031    log "テキストなし"
032    return "クリップボードに\nテキストは\nありませんでした"
033    # set strSetSting to ("クリップボードに\nテキストは\nありませんでした") as text
034    # set ocidReadString to refMe's NSMutableString's alloc()'s initWithString:(strSetSting)
035end if
036
037
038
AppleScriptで生成しました

|

画像データをクリップボードにPDF形式で入れる


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#  com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use framework "PDFKit"
010use scripting additions
011
012property refMe : a reference to current application
013
014################################
015#ダイアログ
016set strName to (name of current application) as text
017if strName is "osascript" then
018  tell application "Finder" to activate
019else
020  tell current application to activate
021end if
022
023set appFileManager to refMe's NSFileManager's defaultManager()
024set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
025set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
026set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
027set listUTI to {"public.image"}
028set strMes to ("ファイルを選んでください") as text
029set strPrompt to ("ファイルを選んでください") as text
030try
031  ### ファイル選択時
032  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDesktopDirPath) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
033on error
034  log "エラーしました"
035  return "エラーしました"
036end try
037
038################################
039#入力パス
040set strFilePath to (POSIX path of aliasFilePath) as text
041set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
042set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
043set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
044
045################################
046#NSData's
047set ocidOption to (refMe's NSDataReadingMappedIfSafe)
048set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
049if (item 2 of listResponse) = (missing value) then
050  log "正常処理"
051  set ocidReadData to (item 1 of listResponse)
052else if (item 2 of listResponse) ≠ (missing value) then
053  set strErrorNO to (item 2 of listDone)'s code() as text
054  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
055  refMe's NSLog("■:" & strErrorNO & strErrorMes)
056  return "エラーしました" & strErrorNO & strErrorMes
057end if
058################################
059#NSImage's
060set ocidReadImage to refMe's NSImage's alloc()'s initWithData:(ocidReadData)
061
062################################
063#PDFPage's
064set ocidPDFPage to refMe's PDFPage's alloc()'s initWithImage:(ocidReadImage)
065
066################################
067#PDFDocument's
068set ocidPDFDoc to refMe's PDFDocument's alloc()'s init()
069ocidPDFDoc's insertPage:(ocidPDFPage) atIndex:(0)
070
071################################
072#NSData
073set ocidPDFData to ocidPDFDoc's dataRepresentation()
074
075################################
076#ペーストボード宣言
077set appPasteboard to refMe's NSPasteboard's generalPasteboard()
078appPasteboard's clearContents()
079#基本はPDF
080appPasteboard's setData:(ocidPDFData) forType:(refMe's NSPasteboardTypePDF)
081#アノテーション形式で入れれば大丈夫か?と思ったがダメだった
082#appPasteboard's setData:(ocidPDFData) forType:("com.apple.AnnotationKit.AnnotationItem")
083#基本系
084#appPasteboard's setData:(ocidPDFData) forType:("Apple PDF pasteboard type")
085#PDFのUTI指定
086#appPasteboard's setData:(ocidPDFData) forType:("com.adobe.pdf")
087#QTのクリップボードデータ(FoxIt)
088#appPasteboard's setData:(ocidPDFData) forType:("com.trolltech.anymime.FPMDATA")
089#Acrobatのスタンプデータ
090#appPasteboard's setData:(ocidPDFData) forType:("ASEL")
091
AppleScriptで生成しました

|

クリップボードの中身で保存可能なものをファイルに保存する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# クリップボードの中身で保存可能なものを
005# ダウンロードフォルダに保存します
006# com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use framework "UniformTypeIdentifiers"
012use scripting additions
013
014property refMe : a reference to current application
015
016################################
017##### パス関連
018################################
019###フォルダ名用に時間を取得する
020set strDateno to doGetDateNo("yyyyMMdd-hhmmss") as text
021###保存先
022set appFileManager to refMe's NSFileManager's defaultManager()
023set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
024set ocidDownloadsDirPathURL to ocidURLsArray's firstObject()
025set strSubDirName to ("Pasteboard/" & strDateno) as text
026set ocidSaveParentsDirPathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:(strSubDirName) isDirectory:(true)
027#フォルダ生成
028set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
029ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
030set listDone to appFileManager's createDirectoryAtURL:(ocidSaveParentsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
031if (item 1 of listDone) is true then
032  log "正常処理"
033else if (item 2 of listDone) ≠ (missing value) then
034  set strErrorNO to (item 2 of listDone)'s code() as text
035  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
036  refMe's NSLog("■:" & strErrorNO & strErrorMes)
037  return "エラーしました" & strErrorNO & strErrorMes
038end if
039
040################################
041######ペーストボードを取得
042################################
043set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
044#タイプを取得
045set ocidPastBoardTypeArray to ocidPasteboard's types()
046#全タイプ処理する
047repeat with itemPastType in ocidPastBoardTypeArray
048  #【1】全タイプ処理 拡張子を決めておく
049  if (itemPastType as text) is "public.utf8-plain-text" then
050    set strExtension to ("utf8.txt") as text
051  else if (itemPastType as text) is "public.utf16-external-plain-text" then
052    set strExtension to ("utf16.txt") as text
053  else
054    #UTTypeを取得
055    set ocidUTType to (refMe's UTType's typeWithIdentifier:(itemPastType))
056    #取得できない
057    if ocidUTType = (missing value) then
058      set strExtension to (missing value)
059    else if ocidUTType ≠ (missing value) then
060      set ocidExtension to (ocidUTType's preferredFilenameExtension())
061      if ocidExtension = (missing value) then
062        set strExtension to (missing value)
063      else
064        set strExtension to (ocidExtension) as text
065      end if
066    end if
067  end if
068  #【2】データを取得
069  if strExtension = (missing value) then
070    #拡張子がわからなかったモノは処理しない
071  else
072    log strExtension
073    #データ取り出し
074    set ocidPastBoardData to (ocidPasteboard's dataForType:(itemPastType))
075    #保存先パス
076    #ファイル名はUTI
077    set ocidBaseFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(itemPastType) isDirectory:(false))
078    #拡張子つけて
079    set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:(strExtension))
080    #保存
081    set ocidOption to (refMe's NSDataWritingAtomic)
082    set listDone to (ocidPastBoardData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference))
083    if (item 1 of listDone) is true then
084      log "正常処理"
085    else if (item 2 of listDone) ≠ (missing value) then
086      set strErrorNO to (item 2 of listDone)'s code() as text
087      set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
088      refMe's NSLog("■:" & strErrorNO & strErrorMes)
089      return "エラーしました" & strErrorNO & strErrorMes
090    end if
091  end if
092end repeat
093
094################################
095##### 保存先を開く
096################################
097set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
098set boolDone to appSharedWorkspace's openURL:(ocidSaveParentsDirPathURL)
099
100
101################################
102##### ファイル名用の時間
103################################
104to doGetDateNo(strDateFormat)
105  ####日付情報の取得
106  set ocidDate to current application's NSDate's |date|()
107  ###日付のフォーマットを定義
108  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
109  ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
110  ocidNSDateFormatter's setDateFormat:strDateFormat
111  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
112  set strDateAndTime to ocidDateAndTime as text
113  return strDateAndTime
114end doGetDateNo
AppleScriptで生成しました

|

クリップボードからファイルパスを取得(少し改良)


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

#!/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
#URL要素の確認
set boolFileName to ocidPastBoardTypeArray's containsObject:(refMe's NSFilenamesPboardType)
set boolFileURL to ocidPastBoardTypeArray's containsObject:("public.file-url")
set boolAppleURL to ocidPastBoardTypeArray's containsObject:("Apple URL pasteboard type")
#URL要素の取得
if boolFileName is true then
  ###NSFilenamesPboardTypeはUNIXパス形式
  set ocidFilePathArray to ocidPasteboard's propertyListForType:(refMe's NSFilenamesPboardType)
else if boolFileName is false then
  if boolFileURL is true then
    ##public.file-url の場合はNSURLのクラスを指定して取得した後でパス指定する
    set ocidClassesArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidClassesArrayM's addObject:((refMe's NSURL)'s class)
    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
  else if boolFileURL is false then
    ##Apple URL pasteboard typeにはURLは1つだけしか格納されない
    set ocidAppleURLArray to ocidPasteboard's propertyListForType:("Apple URL pasteboard type")
    set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
    try
      repeat with itemArray in ocidAppleURLArray
        if itemArray ≠ (missing value) then
          set ocidFilePathURL to (refMe's NSURL's URLWithString:(itemArray))
(ocidFilePathArray's addObject:(ocidFilePathURL's |path|))
        end if
      end repeat
    on error
      set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
(ocidFilePathArray's addObject:("ファイルのパスの取得に失敗しました"))
    end try
  else
    set ocidFilePathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
(ocidFilePathArray's addObject:("ファイルのパスの取得に失敗しました"))
  end if
end if

########################
## 出力用のテキストにする
########################
set ocidOutPutString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
repeat with itemArray in ocidFilePathArray
(ocidOutPutString's appendString:(itemArray))
(ocidOutPutString's appendString:("\n"))
end repeat
set strOutPutString to ocidOutPutString as text

########################
## ダイアログ
########################
##前面に
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 aliasIconPath to (POSIX file "/System/Library/CoreServices/Finder.app/Contents/Resources/Finder.icns")
try
  set recordResult to (display dialog strOutPutString with title "戻り値です" default answer strOutPutString buttons {"クリップボードにコピー", "終了", "Finderに表示"} default button "Finderに表示" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
on error
return "エラーしました"
end try
if (gave up of recordResult) is true then
return "時間切れです"
end if
##############################
#####Finderに表示
##############################

if button returned of recordResult is "Finderに表示" then
  ##NSWorkspaceで
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidOpenURLsArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
  repeat with itemFilePath in ocidFilePathArray
    set ocidFilePath to itemFilePath's stringByStandardizingPath()
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
(ocidOpenURLsArray's addObject:(ocidFilePathURL))
  end repeat
  ##SelectingURLsを実行する
appSharedWorkspace's activateFileViewerSelectingURLs:(ocidOpenURLsArray)
  
end if
##############################
#####値のコピー
##############################
if button returned of recordResult is "クリップボードにコピー" then
  try
    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)
  on error
    tell application "Finder"
      set the clipboard to strText as text
    end tell
  end try
end if


return 0



|

ペーストボードの内容(テキスト)に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


|

その他のカテゴリー

Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation 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 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 Apple AppleScript AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Audio 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 Diff AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript Droplet AppleScript eMail AppleScript Encode % AppleScript Encode Decode AppleScript Encode UTF8 AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript Guide AppleScript HTML AppleScript HTML Entity AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim AppleScript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript Leading Zero AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript Mail AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Messages AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSArray Sort 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 NSFileManager enumeratorAtURL AppleScript NSFont AppleScript NSFontManager AppleScript NSGraphicsContext 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 NSpoint AppleScript NSPredicate AppleScript NSPrintOperation AppleScript NSRange AppleScript NSRect 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 NSURLSession AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotation AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFImageRep AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photoshop AppleScript Pictures 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 Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript Swift AppleScript System Events AppleScript System Events Plist AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text MD 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 savedSearch AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript XMP AppleScript YouTube Applications CityCode github iPhone List lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom Windows zoom