001 | #! /usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # RGBの場合カラーはキャリブレートされた値になります |
---|
004 | # そのためPantone等指定された値とは異なりますが |
---|
005 | # デバイスのモニター設定の値が反映されています |
---|
006 | # com.cocolog-nifty.quicktimer.icefloe |
---|
007 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
008 | use AppleScript version "2.8" |
---|
009 | use framework "Foundation" |
---|
010 | use framework "AppKit" |
---|
011 | use scripting additions |
---|
012 | |
---|
013 | #このファイルのパス |
---|
014 | set aliasPathToMe to (path to me) as alias |
---|
015 | tell application "Finder" |
---|
016 | #コンテナ |
---|
017 | set aliasContainerDirPath to (container of aliasPathToMe) as alias |
---|
018 | #Swift格納先 |
---|
019 | set aliasBinDirPath to (folder "bin" of folder aliasContainerDirPath) as alias |
---|
020 | #Swiftパス |
---|
021 | set aliasSwiftPath to (file "launchColorPicker.swift" of folder aliasBinDirPath) as alias |
---|
022 | end tell |
---|
023 | #パス |
---|
024 | set strSwiftPath to (POSIX path of aliasSwiftPath) as text |
---|
025 | #コマンド整形 zsh指定 |
---|
026 | set strCommandText to ("/bin/zsh -c '" & strSwiftPath & "'") as text |
---|
027 | log strCommandText |
---|
028 | try |
---|
029 | #コマンド実行 |
---|
030 | set strResponse to (do shell script strCommandText) as text |
---|
031 | end try |
---|
032 | #スペース区切りでリスト化 |
---|
033 | set strDelim to AppleScript's text item delimiters |
---|
034 | set AppleScript's text item delimiters to " " |
---|
035 | set listResponse to every text item of strResponse |
---|
036 | set AppleScript's text item delimiters to strDelim |
---|
037 | #数えて |
---|
038 | set numCntList to (count of listResponse) as integer |
---|
039 | ##単純にカラーの数で取得 |
---|
040 | if (strResponse) contains "Gray" then |
---|
041 | set numK to (item (numCntList - 1) of listResponse) as number |
---|
042 | set numA to (item (numCntList) of listResponse) as number |
---|
043 | set numKp to (numK * 100) as integer |
---|
044 | set numAp to (numA * 100) as integer |
---|
045 | set strMes to ("Gs: " & numK & "\t" & numA & "") as text |
---|
046 | set strResponseText to ("0\t0\t0\t" & numKp & "\t") as text |
---|
047 | |
---|
048 | else if (strResponse) contains "CMYK" then |
---|
049 | set numC to (item (numCntList - 4) of listResponse) as number |
---|
050 | set numM to (item (numCntList - 3) of listResponse) as number |
---|
051 | set numY to (item (numCntList - 2) of listResponse) as number |
---|
052 | set numK to (item (numCntList - 1) of listResponse) as number |
---|
053 | set numA to (item (numCntList) of listResponse) as number |
---|
054 | set numCp to (numC * 100) as integer |
---|
055 | set numMp to (numM * 100) as integer |
---|
056 | set numYp to (numY * 100) as integer |
---|
057 | set numKp to (numK * 100) as integer |
---|
058 | set numAp to (numA * 100) as integer |
---|
059 | set strMes to ("CMYK値: " & numC & "\t" & numM & "\t" & numY & "\t" & numK & "\t" & numA & "") as text |
---|
060 | set strResponseText to ("" & numCp & "\t" & numMp & "\t" & numYp & "\t" & numKp & "\t") as text |
---|
061 | |
---|
062 | else |
---|
063 | ##それ以外はまぁRGB系でしょう |
---|
064 | set numR to (item (numCntList - 3) of listResponse) as number |
---|
065 | set numG to (item (numCntList - 2) of listResponse) as number |
---|
066 | set numB to (item (numCntList - 1) of listResponse) as number |
---|
067 | set numA to (item (numCntList) of listResponse) as number |
---|
068 | set numR8 to (numR * 255) as integer |
---|
069 | set numG8 to (numG * 255) as integer |
---|
070 | set numB8 to (numB * 255) as integer |
---|
071 | set numA8 to (numA * 255) as integer |
---|
072 | set strMes to ("RGB値: " & numR & "\t" & numG & "\t" & numB & "\t" & numA & "") as text |
---|
073 | set strResponseText to ("" & numR8 & "\t" & numG8 & "\t" & numB8 & "\t") as text |
---|
074 | end if |
---|
075 | |
---|
076 | |
---|
077 | ############################## |
---|
078 | #####ダイアログ |
---|
079 | ############################## |
---|
080 | tell current application |
---|
081 | set strName to name as text |
---|
082 | end tell |
---|
083 | if strName is "osascript" then |
---|
084 | tell application "Finder" |
---|
085 | activate |
---|
086 | end tell |
---|
087 | else |
---|
088 | tell current application |
---|
089 | activate |
---|
090 | end tell |
---|
091 | end if |
---|
092 | set aliasIconPath to (POSIX file "/System/Applications/Utilities/Digital Color Meter.app/Contents/Resources/AppIcon.icns") as alias |
---|
093 | try |
---|
094 | set recordResult to (display dialog strMes with title "戻り値です" default answer strResponseText buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record |
---|
095 | on error |
---|
096 | return "エラーしました" |
---|
097 | end try |
---|
098 | if (gave up of recordResult) is true then |
---|
099 | return "時間切れです" |
---|
100 | end if |
---|
101 | ############################## |
---|
102 | #####自分自身を再実行 |
---|
103 | ############################## |
---|
104 | if button returned of recordResult is "再実行" then |
---|
105 | tell application "Finder" |
---|
106 | set aliasPathToMe to (path to me) as alias |
---|
107 | end tell |
---|
108 | run script aliasPathToMe with parameters "再実行" |
---|
109 | end if |
---|
110 | ############################## |
---|
111 | #####値のコピー |
---|
112 | ############################## |
---|
113 | if button returned of recordResult is "クリップボードにコピー" then |
---|
114 | try |
---|
115 | set strText to text returned of recordResult as text |
---|
116 | ####ペーストボード宣言 |
---|
117 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
---|
118 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
---|
119 | appPasteboard's clearContents() |
---|
120 | appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString) |
---|
121 | on error |
---|
122 | tell application "Finder" |
---|
123 | set the clipboard to strText as text |
---|
124 | end tell |
---|
125 | end try |
---|
126 | end if |
---|
127 | |
---|
128 | |
---|
129 | return 0 |
---|