Unit Conversion

縦横比計算(修正 1対Xを追加)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004(*
005ダイアログ部ベーススクリプト
006https://www.macscripter.net/t/edit-db123s-dialog-for-use-with-asobjc/73636/2
007*)
008#com.cocolog-nifty.quicktimer.icefloe
009----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
010use AppleScript version "2.8"
011use framework "Foundation"
012use framework "UniformTypeIdentifiers"
013use framework "AppKit"
014#use framework "Carbon"
015use scripting additions
016property refMe : a reference to current application
017
018doDialoge()
019
020#####################
021###
022property appDialogWindow : missing value
023property strOneTextField : missing value
024property strTwoTextField : missing value
025property appCancelButton : missing value
026property appOkButton : missing value
027property strOne : missing value
028property strTwo : missing value
029property appOkClicked : false
030property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
031
032
033to doDialoge()
034  
035  ##############################
036  #####ダイアログ
037  ##############################
038  tell current application
039    set strName to name as text
040  end tell
041  ####スクリプトメニューから実行したら
042  if strName is "osascript" then
043    tell application "Finder"
044      activate
045    end tell
046  else
047    tell current application
048      activate
049    end tell
050  end if
051  
052  set dialogResult to my doShowDialog()
053  if dialogResult is missing value then
054    return "【エラー】キャンセルしました"
055  end if
056  set strReturnedTextX to strOne of dialogResult
057  set strReturnedTextY to strTwo of dialogResult
058  
059  ##############################
060  #####戻り値整形
061  ##############################
062  set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedTextX))
063  ###タブと改行を除去しておく
064  set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
065  ocidTextM's appendString:(ocidResponseText)
066  ##改行除去
067  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
068  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
069  ##タブ除去
070  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
071  ####戻り値を半角にする
072  set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
073  set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
074  ##カンマ置換
075  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:(",") withString:(".")
076  ###数字以外の値を取る
077  #set ocidDecSet to refMe's NSCharacterSet's decimalDigitCharacterSet
078  #set ocidCharSet to ocidDecSet's invertedSet()
079  #set ocidCharArray to ocidResponseHalfwidth's componentsSeparatedByCharactersInSet:ocidCharSet
080  #set ocidInteger to ocidCharArray's componentsJoinedByString:""
081  ###テキストにしてから
082  set strTextM to ocidTextM as text
083  ###数値に
084  set strReturnedTextX to strTextM as number
085  
086  ###
087  set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedTextY))
088  ###タブと改行を除去しておく
089  set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
090  ocidTextM's appendString:(ocidResponseText)
091  ##改行除去
092  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
093  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
094  ##タブ除去
095  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
096  ####戻り値を半角にする
097  set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
098  set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
099  ##カンマ置換
100  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:(",") withString:(".")
101  ###数字以外の値を取る
102  #set ocidDecSet to refMe's NSCharacterSet's decimalDigitCharacterSet
103  #set ocidCharSet to ocidDecSet's invertedSet()
104  #set ocidCharArray to ocidResponseHalfwidth's componentsSeparatedByCharactersInSet:ocidCharSet
105  #set ocidInteger to ocidCharArray's componentsJoinedByString:""
106  ###テキストにしてから
107  set strTextM to ocidTextM as text
108  ###数値に
109  set strReturnedTextY to strTextM as number
110  
111  ##############################
112  #####計算部
113  ##############################
114  
115  if (strReturnedTextX as number) ≥ (strReturnedTextY as number) then
116    set numRaw to (strReturnedTextX / strReturnedTextY) as number
117  else if (strReturnedTextY as number) > (strReturnedTextX as number) then
118    set numRaw to (strReturnedTextY / strReturnedTextX) as number
119  end if
120  ###
121  set ocidDecimalNumber to refMe's NSDecimalNumber's decimalNumberWithString:(numRaw as text)
122  set appNumberFormatter to refMe's NSNumberFormatter's alloc()'s init()
123  appNumberFormatter's setPositiveFormat:("#,##0.00")
124  set ocidRetio to appNumberFormatter's stringFromNumber:(ocidDecimalNumber)
125  ###そのまま
126  set strMes to ("計算結果です: 1 対 " & (ocidRetio as text) & " \r") as text
127  set strMes to ("Number値: " & numRaw & " \r") as text
128  ###整数切り捨て
129  set intDown to ((round of ((numRaw) * 1000) rounding down) / 1000) * 100 as number
130  log intDown
131  set strMes to (strMes & "パーセント:" & intDown & "% \r") as text
132  
133  ###切り捨て 小数点2
134  set num2Dec to ((round of ((numRaw) * 100) rounding down) / 100) as number
135  log num2Dec
136  set strMes to (strMes & "小数点2位:" & num2Dec & "\r") as text
137  ###切り捨て 小数点3
138  set num3Dec to ((round of ((numRaw) * 1000) rounding down) / 1000) as number
139  log num3Dec
140  set strMes to (strMes & "小数点3位:" & num3Dec & "\r") as text
141  ###切り捨て 小数点4
142  set num4Dec to ((round of ((numRaw) * 10000) rounding down) / 10000) as number
143  log num4Dec
144  set strMes to (strMes & "小数点4位:" & num4Dec & "\r") as text
145  ####
146  set strMes to (strMes & "小数点以下計算は切り捨て\r") as text
147  ##############################
148  #####ダイアログ
149  ##############################
150  tell current application
151    set strName to name as text
152  end tell
153  ####スクリプトメニューから実行したら
154  if strName is "osascript" then
155    tell application "Finder"
156      activate
157    end tell
158  else
159    tell current application
160      activate
161    end tell
162  end if
163  set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
164  
165  try
166    set recordResult to (display dialog strMes with title strMes default answer numRaw buttons {"クリップボードにコピー", "もう一度", "終了"} default button "もう一度" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
167  on error
168    log "エラーしました"
169    return
170  end try
171  log recordResult
172  if button returned of recordResult is "もう一度" then
173    doDialoge()
174  else if (gave up of recordResult) is true then
175    return "時間切れです"
176    
177  end if
178  ##############################
179  #####値のコピー
180  ##############################
181  if button returned of recordResult is "クリップボードにコピー" then
182    try
183      set strText to text returned of recordResult as text
184      ####ペーストボード宣言
185      set appPasteboard to refMe's NSPasteboard's generalPasteboard()
186      set ocidText to (refMe's NSString's stringWithString:(strText))
187      appPasteboard's clearContents()
188      appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
189    on error
190      tell application "Finder"
191        set the clipboard to strText as text
192      end tell
193    end try
194  end if
195end doDialoge
196
197
198
199####################################
200###### ダイアログ
201####################################
202
203on doShowDialog()
204  if refMe's AEInteractWithUser(-1, missing value, missing value) ≠ 0 then
205    return missing value
206  end if
207  if refMe's NSThread's isMainThread() then
208    my doPerformDialog:(missing value)
209  else
210    its performSelectorOnMainThread:("doPerformDialog:") withObject:(missing value) waitUntilDone:true
211  end if
212  if my appOkClicked then
213    return {strOne:my strOne as text, strTwo:my strTwo as text}
214  end if
215  return missing value
216end doShowDialog
217
218on doPerformDialog:(args)
219  set strOneLabel to refMe's NSTextField's labelWithString:("X size:")
220  strOneLabel's setFrame:(refMe's NSMakeRect(20, 85, 70, 20))
221  
222  set my strOneTextField to refMe's NSTextField's textFieldWithString:""
223  strOneTextField's setFrame:(refMe's NSMakeRect(87, 85, 245, 20))
224  strOneTextField's setEditable:true
225  strOneTextField's setBordered:true
226  strOneTextField's setPlaceholderString:("X数値のみ")
227  strOneTextField's setDelegate:(me)
228  
229  set strTwoLabel to refMe's NSTextField's labelWithString:("Y size:")
230  strTwoLabel's setFrame:(refMe's NSMakeRect(20, 55, 70, 20))
231  
232  set my strTwoTextField to refMe's NSTextField's textFieldWithString:("")
233  strTwoTextField's setFrame:(refMe's NSMakeRect(87, 55, 245, 20))
234  strTwoTextField's setEditable:true
235  strTwoTextField's setBordered:true
236  strTwoTextField's setPlaceholderString:("Y数値のみ")
237  
238  set my appCancelButton to refMe's NSButton's buttonWithTitle:"Cancel" target:me action:"doButtonAction:"
239  appCancelButton's setFrameSize:{94, 32}
240  appCancelButton's setFrameOrigin:{150, 10}
241  appCancelButton's setKeyEquivalent:(character id 27)
242  
243  set my appOkButton to refMe's NSButton's buttonWithTitle:"OK" target:me action:"doButtonAction:"
244  appOkButton's setFrameSize:{94, 32}
245  appOkButton's setFrameOrigin:{245, 10}
246  appOkButton's setKeyEquivalent:return
247  appOkButton's setEnabled:false
248  
249  set ocidWindowSize to refMe's NSMakeRect(0, 0, 355, 125)
250  set ocidWinStyle to (refMe's NSWindowStyleMaskTitled as integer) + (refMe's NSWindowStyleMaskClosable as integer)
251  set my appDialogWindow to refMe's NSWindow's alloc()'s initWithContentRect:(ocidWindowSize) styleMask:(ocidWinStyle) backing:(refMe's NSBackingStoreBuffered) defer:true
252  
253  appDialogWindow's contentView()'s addSubview:(strOneLabel)
254  appDialogWindow's contentView()'s addSubview:(strOneTextField)
255  appDialogWindow's contentView()'s addSubview:(strTwoLabel)
256  appDialogWindow's contentView()'s addSubview:(strTwoTextField)
257  appDialogWindow's contentView()'s addSubview:(appCancelButton)
258  appDialogWindow's contentView()'s addSubview:(appOkButton)
259  
260  appDialogWindow's setTitle:"比率換算"
261  appDialogWindow's setLevel:(refMe's NSModalPanelWindowLevel)
262  appDialogWindow's setDelegate:(me)
263  appDialogWindow's orderFront:(me)
264  appDialogWindow's |center|()
265  
266  refMe's NSApp's activateIgnoringOtherApps:true
267  refMe's NSApp's runModalForWindow:(appDialogWindow)
268end doPerformDialog:
269
270on doButtonAction:(sender)
271  if sender is my appOkButton then
272    set my strOne to strOneTextField's stringValue()
273    set my strTwo to strTwoTextField's stringValue()
274    set my appOkClicked to true
275  end if
276  my appDialogWindow's |close|()
277end doButtonAction:
278
279on controlTextDidChange:(objNotification)
280  set sender to objNotification's object()
281  if sender is my strOneTextField then
282    if sender's stringValue() as text"" then
283      my (appOkButton's setEnabled:true)
284    else
285      my (appOkButton's setEnabled:false)
286    end if
287  end if
288end controlTextDidChange:
289
290on windowWillClose:(objNotification)
291  refMe's NSApp's stopModal()
292end windowWillClose:
AppleScriptで生成しました

|

mm to pt


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 scripting additions
012
013property refMe : a reference to current application
014
015set strPt to doConversionMM2PT(30)
016log 30 & "mmは"
017log strPt & "ptは"
018return strPt
019
020
021############################
022# mmをPTに換算
023############################
024to doConversionMM2PT(argNumMM)
025  set strArgNumMM to argNumMM as text
026  #指数
027  set ocidCm2InchNo to refMe's NSDecimalNumber's alloc()'s initWithString:("25.4")
028  set ocidDivPt to refMe's NSDecimalNumber's alloc()'s initWithString:("72")
029  set ocidDivNo to (ocidCm2InchNo's decimalNumberByDividingBy:(ocidDivPt))
030  #計算
031  set ocidDecNo to refMe's NSDecimalNumber's alloc()'s initWithString:(strArgNumMM)
032  set ocidRawNo to (ocidDecNo's decimalNumberByDividingBy:(ocidDivNo))
033  #小数点以下切り上げ
034  set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init()
035  ocidFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundCeiling)
036  ocidFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)
037  ocidFormatter's setMaximumFractionDigits:(4)
038  set ocidRoundCeiling to ocidFormatter's stringFromNumber:(ocidRawNo)
039  #ポイントサイズ
040  set strPtSize to ocidRoundCeiling as text
041  set numPtSize to strPtSize as number
042  
043  return numPtSize
044  
045end doConversionMM2PT
046
047
AppleScriptで生成しました

|

[単位換算]ptをmmに


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.6"
007use framework "Foundation"
008use framework "AppKit"
009use scripting additions
010
011property refMe : a reference to current application
012
013
014
015set listInput to {{72, 144}, {288, 360}} as list
016
017log doNestListToCSV(listInput) as text
018
019
020#####################################
021#【1】PT{{x,y},{w,h}}をMMテキストの"x,y,w,h"
022#####################################
023to doNestListToCSV(argNestList)
024  #3を実行
025  set listTmpList to doDisChildArray(argNestList)
026  #4を実行
027  set listMM to doLitPtToListMM(listTmpList)
028  #2を実行
029  set strCSV to doListToCSV(listMM)
030  return strCSV
031end doNestListToCSV
032
033#####################################
034#【2】リスト{x,y,w,h}をテキストの"x,y,w,h"に
035#####################################
036to doListToCSV(argList)
037  set ocidArray to refMe's NSArray's arrayWithArray:(argList)
038  set ocidCSV to (ocidArray's componentsJoinedByString:(","))
039  set strCSV to ocidCSV as text
040  return strCSV
041end doListToCSV
042
043#####################################
044#【3】 {{x,y},{w,h}}  を{x,y,w,h}のリストに
045#####################################
046to doDisChildArray(argList)
047  set listOutPut to {} as list
048  repeat with itemChildArray in argList
049    repeat with itemArray in itemChildArray
050      copy itemArray to end of listOutPut
051    end repeat
052  end repeat
053  return listOutPut
054end doDisChildArray
055
056
057#####################################
058#【4】PT {x,y,w,h}をMM{x,y,w,h}のリストに
059#####################################
060to doLitPtToListMM(argPtList)
061  set listOutPut to {} as list
062  repeat with itemPt in argPtList
063    set strMM to doPtToMm(itemPt)
064    copy strMM to end of listOutPut
065  end repeat
066  return listOutPut
067end doLitPtToListMM
068
069##############################
070#PT to MM 小数点以下2位まで
071##############################
072to doPtToMm(argNumberPtString)
073  set strNumberPt to argNumberPtString as text
074  #割り算
075  set ocidDecNo to refMe's NSDecimalNumber's alloc()'s initWithString:(strNumberPt)
076  set ocidDecPt to refMe's NSDecimalNumber's alloc()'s initWithString:("72")
077  set ocidNoDivPt to (ocidDecNo's decimalNumberByDividingBy:(ocidDecPt))
078  #掛け算
079  set ocidDecInch to refMe's NSDecimalNumber's alloc()'s initWithString:("25.4")
080  set ocidDecMM to (ocidNoDivPt's decimalNumberByMultiplyingBy:(ocidDecInch))
081  ###小数点2位まで
082  set appFormatter to refMe's NSNumberFormatter's alloc()'s init()
083  appFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundHalfUp)
084  appFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)
085  appFormatter's setMaximumFractionDigits:(2)
086  #テキストにして戻す
087  set ocidMM to appFormatter's stringFromNumber:(ocidDecMM)
088  set strMM to ocidMM as text
089  return strMM
090end doPtToMm
091
092
093
AppleScriptで生成しました

|

縦横ピクセルサイズと対角のインチサイズから画面解像度を求める(デバイス用)

要はこの計算です
Buzud002
AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# ピクセルサイズと 対角インチから 解像度を計算します
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011#use framework "math"
012use scripting additions
013property refMe : a reference to current application
014
015##############################
016#####ダイアログ
017##############################
018tell current application
019  set strName to name as text
020end tell
021####スクリプトメニューから実行したら
022if strName is "osascript" then
023  tell application "Finder"
024    activate
025  end tell
026else
027  tell current application
028    activate
029  end tell
030end if
031#####ダイアログ実行
032set recordDialogResult to my doShowDialog()
033if recordDialogResult is missing value then
034  return "【エラー】キャンセルしました"
035end if
036#####DICTにする
037set ocidResultsDict to refMe's NSMutableDictionary's alloc()'s initWithDictionary:(recordDialogResult)
038set ocidAllKeys to ocidResultsDict's allKeys()
039repeat with itemKey in ocidAllKeys
040  set ocidGetValue to (ocidResultsDict's objectForKey:(itemKey))'s mutableCopy()
041  #改行とタブを除去
042  set ocidSetValue to (ocidGetValue's stringByReplacingOccurrencesOfString:("\n") withString:(""))
043  set ocidSetValue to (ocidSetValue's stringByReplacingOccurrencesOfString:("\r") withString:(""))
044  set ocidSetValue to (ocidSetValue's stringByReplacingOccurrencesOfString:("\t") withString:(""))
045  (ocidResultsDict's setObject:(ocidSetValue) forKey:(itemKey))
046end repeat
047##ダイアログの戻り値を数値に 半角変換も念の為
048set ocidSetString to ocidResultsDict's valueForKey:("strOne")
049set ocidSetValue to ocidSetString's stringByApplyingTransform:(refMe's NSStringTransformFullwidthToHalfwidth) |reverse|:(false)
050set ocidW to (refMe's NSDecimalNumber's alloc()'s initWithString:(ocidSetValue))
051set ocidSetString to ocidResultsDict's valueForKey:("strTwo")
052set ocidSetValue to ocidSetString's stringByApplyingTransform:(refMe's NSStringTransformFullwidthToHalfwidth) |reverse|:(false)
053set ocidH to (refMe's NSDecimalNumber's alloc()'s initWithString:(ocidSetValue))
054set ocidSetString to ocidResultsDict's valueForKey:("strThr")
055set ocidSetValue to ocidSetString's stringByApplyingTransform:(refMe's NSStringTransformFullwidthToHalfwidth) |reverse|:(false)
056set ocidD to (refMe's NSDecimalNumber's alloc()'s initWithString:(ocidSetValue))
057##############################
058#####計算部
059##############################
060#2乗
061set ocidWsq to (ocidW's decimalNumberByRaisingToPower:(2))
062set ocidHsq to (ocidH's decimalNumberByRaisingToPower:(2))
063#足す
064set ocidWHsq to ocidWsq's decimalNumberByAdding:(ocidHsq)
065#√ ルート計算のOBJECTIV-Cの計算方法がわからなかったので
066#従来方式で計算している
067set strDiag to ((ocidWHsq as real) ^ 0.5) as text
068set ocidDiag to (refMe's NSDecimalNumber's alloc()'s initWithString:(strDiag))
069
070#解像度
071set ocidPPI to ocidDiag's decimalNumberByDividingBy:(ocidD)
072#整数に
073set numPPI to ocidPPI as integer
074##ダイアログに渡すテキスト
075set strMes to ("おおよその画面解像度(ピクセル密度)は\n" & (numPPI as text) & " ppiです") as text
076##############################
077#####ダイアログ
078##############################
079tell current application
080  set strName to name as text
081end tell
082####スクリプトメニューから実行したら
083if strName is "osascript" then
084  tell application "Finder"
085    activate
086  end tell
087else
088  tell current application
089    activate
090  end tell
091end if
092set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
093try
094  set recordResult to (display dialog strMes with title "画像解像度(ピクセル密度 ppi)" default answer strMes buttons {"クリップボードにコピー", "キャンセル", "再実行"} default button "再実行" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) as record
095on error
096  log "エラーしました"
097  return "キャンセルしました"
098end try
099if (gave up of recordResult) is true then
100  return "時間切れです"
101end if
102###自分自身を再実行
103if button returned of recordResult is "再実行" then
104  tell application "Finder"
105    set aliasPathToMe to (path to me) as alias
106  end tell
107  run script aliasPathToMe
108end if
109##############################
110#####値のコピー
111##############################
112if button returned of recordResult is "クリップボードにコピー" then
113  try
114    set strText to text returned of recordResult as text
115    ####ペーストボード宣言
116    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
117    set ocidText to (refMe's NSString's stringWithString:(strText))
118    appPasteboard's clearContents()
119    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
120  on error
121    tell application "Finder"
122      set the clipboard to strText as text
123    end tell
124  end try
125end if
126
127####################################
128(*    ダイアログ
129ダイアログ部ベーススクリプト
130https://www.macscripter.net/t/edit-db123s-dialog-for-use-with-asobjc/73636/2
131*)
132####################################
133property appDialogWindow : missing value
134property strOneTextField : missing value
135property strTwoTextField : missing value
136property strThrTextField : missing value
137property appCancelButton : missing value
138property appOkButton : missing value
139property strOne : missing value
140property strTwo : missing value
141property strThr : missing value
142property appOkClicked : false
143property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
144
145on doShowDialog()
146  if refMe's AEInteractWithUser(-1, missing value, missing value) ≠ 0 then
147    return missing value
148  end if
149  if refMe's NSThread's isMainThread() then
150    my doPerformDialog:(missing value)
151  else
152    its performSelectorOnMainThread:("doPerformDialog:") withObject:(missing value) waitUntilDone:true
153  end if
154  if my appOkClicked then
155    return {strOne:my strOne as text, strTwo:my strTwo as text, strThr:my strThr as text}
156  end if
157  return missing value
158end doShowDialog
159
160on doPerformDialog:(args)
161  ####strOne
162  set strOneLabel to refMe's NSTextField's labelWithString:("幅px:")
163  strOneLabel's setFrame:(refMe's NSMakeRect(20, 115, 70, 20))
164  set my strOneTextField to refMe's NSTextField's textFieldWithString:""
165  strOneTextField's setFrame:(refMe's NSMakeRect(87, 115, 245, 20))
166  strOneTextField's setEditable:true
167  strOneTextField's setBordered:true
168  strOneTextField's setPlaceholderString:("pxサイズ整数")
169  ####strTwo
170  set strTwoLabel to refMe's NSTextField's labelWithString:("縦px:")
171  strTwoLabel's setFrame:(refMe's NSMakeRect(20, 85, 70, 20))
172  set my strTwoTextField to refMe's NSTextField's textFieldWithString:("")
173  strTwoTextField's setFrame:(refMe's NSMakeRect(87, 85, 245, 20))
174  strTwoTextField's setEditable:true
175  strTwoTextField's setBordered:true
176  strTwoTextField's setPlaceholderString:("pxサイズ整数")
177  ####strThr
178  set strThrLabel to refMe's NSTextField's labelWithString:("対角inch:")
179  strThrLabel's setFrame:(refMe's NSMakeRect(20, 55, 70, 20))
180  set my strThrTextField to refMe's NSTextField's textFieldWithString:("")
181  strThrTextField's setFrame:(refMe's NSMakeRect(87, 55, 245, 20))
182  strThrTextField's setEditable:true
183  strThrTextField's setBordered:true
184  strThrTextField's setPlaceholderString:("インチ指定")
185  ####setDelegate
186  strThrTextField's setDelegate:(me)
187  ####Cancel
188  set my appCancelButton to refMe's NSButton's buttonWithTitle:"Cancel" target:me action:"doButtonAction:"
189  appCancelButton's setFrameSize:{94, 32}
190  appCancelButton's setFrameOrigin:{150, 10}
191  appCancelButton's setKeyEquivalent:(character id 27)
192  ####OK
193  set my appOkButton to refMe's NSButton's buttonWithTitle:"OK" target:me action:"doButtonAction:"
194  appOkButton's setFrameSize:{94, 32}
195  appOkButton's setFrameOrigin:{245, 10}
196  appOkButton's setKeyEquivalent:return
197  appOkButton's setEnabled:false
198  ####ダイアログ
199  set ocidWindowSize to refMe's NSMakeRect(0, 0, 355, 160)
200  set ocidWinStyle to (refMe's NSWindowStyleMaskTitled as integer) + (refMe's NSWindowStyleMaskClosable as integer)
201  set my appDialogWindow to refMe's NSWindow's alloc()'s initWithContentRect:(ocidWindowSize) styleMask:(ocidWinStyle) backing:(refMe's NSBackingStoreBuffered) defer:true
202  ##各要素をセット
203  appDialogWindow's contentView()'s addSubview:(strOneLabel)
204  appDialogWindow's contentView()'s addSubview:(strOneTextField)
205  appDialogWindow's contentView()'s addSubview:(strTwoLabel)
206  appDialogWindow's contentView()'s addSubview:(strTwoTextField)
207  appDialogWindow's contentView()'s addSubview:(strThrLabel)
208  appDialogWindow's contentView()'s addSubview:(strThrTextField)
209  appDialogWindow's contentView()'s addSubview:(appCancelButton)
210  appDialogWindow's contentView()'s addSubview:(appOkButton)
211  appDialogWindow's setTitle:"画像解像度(ppi)計算"
212  appDialogWindow's setLevel:(refMe's NSModalPanelWindowLevel)
213  appDialogWindow's setDelegate:(me)
214  appDialogWindow's orderFront:(me)
215  appDialogWindow's |center|()
216  #
217  refMe's NSApp's activateIgnoringOtherApps:true
218  refMe's NSApp's runModalForWindow:(appDialogWindow)
219end doPerformDialog:
220
221##送信
222on doButtonAction:(sender)
223  if sender is my appOkButton then
224    set my strOne to strOneTextField's stringValue()
225    set my strTwo to strTwoTextField's stringValue()
226    set my strThr to strThrTextField's stringValue()
227    set my appOkClicked to true
228  end if
229  my appDialogWindow's |close|()
230end doButtonAction:
231##OKボタンをアクティブにするのは3番目のボタンの値が入ってから
232on controlTextDidChange:(objNotification)
233  set sender to objNotification's object()
234  if sender is my strThrTextField then
235    if sender's stringValue() as text"" then
236      my (appOkButton's setEnabled:true)
237    else
238      my (appOkButton's setEnabled:false)
239    end if
240  end if
241end controlTextDidChange:
242
243on windowWillClose:(objNotification)
244  refMe's NSApp's stopModal()
245end windowWillClose:
AppleScriptで生成しました

|

単位換算 詰め合わせ 2024-1

詰め合わせ 再実行対応版

ダウンロード - unitcnv.zip

|

8bitカラー値をhex値に変換


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

#!/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


log getHex(0)
-->(*00*)
log getHex(128)
-->(*80*)
log getHex(255)
-->(*FF*)


##############################
#サブ
##############################
to getHex(arg8BitNum)
  set record8Bit2Hex to {|0|:"00", |1|:"01", |2|:"02", |3|:"03", |4|:"04", |5|:"05", |6|:"06", |7|:"07", |8|:"08", |9|:"09", |10|:"0A", |11|:"0B", |12|:"0C", |13|:"0D", |14|:"0E", |15|:"0F", |16|:"10", |17|:"11", |18|:"12", |19|:"13", |20|:"14", |21|:"15", |22|:"16", |23|:"17", |24|:"18", |25|:"19", |26|:"1A", |27|:"1B", |28|:"1C", |29|:"1D", |30|:"1E", |31|:"1F", |32|:"20", |33|:"21", |34|:"22", |35|:"23", |36|:"24", |37|:"25", |38|:"26", |39|:"27", |40|:"28", |41|:"29", |42|:"2A", |43|:"2B", |44|:"2C", |45|:"2D", |46|:"2E", |47|:"2F", |48|:"30", |49|:"31", |50|:"32", |51|:"33", |52|:"34", |53|:"35", |54|:"36", |55|:"37", |56|:"38", |57|:"39", |58|:"3A", |59|:"3B", |60|:"3C", |61|:"3D", |62|:"3E", |63|:"3F", |64|:"40", |65|:"41", |66|:"42", |67|:"43", |68|:"44", |69|:"45", |70|:"46", |71|:"47", |72|:"48", |73|:"49", |74|:"4A", |75|:"4B", |76|:"4C", |77|:"4D", |78|:"4E", |79|:"4F", |80|:"50", |81|:"51", |82|:"52", |83|:"53", |84|:"54", |85|:"55", |86|:"56", |87|:"57", |88|:"58", |89|:"59", |90|:"5A", |91|:"5B", |92|:"5C", |93|:"5D", |94|:"5E", |95|:"5F", |96|:"60", |97|:"61", |98|:"62", |99|:"63", |100|:"64", |101|:"65", |102|:"66", |103|:"67", |104|:"68", |105|:"69", |106|:"6A", |107|:"6B", |108|:"6C", |109|:"6D", |110|:"6E", |111|:"6F", |112|:"70", |113|:"71", |114|:"72", |115|:"73", |116|:"74", |117|:"75", |118|:"76", |119|:"77", |120|:"78", |121|:"79", |122|:"7A", |123|:"7B", |124|:"7C", |125|:"7D", |126|:"7E", |127|:"7F", |128|:"80", |129|:"81", |130|:"82", |131|:"83", |132|:"84", |133|:"85", |134|:"86", |135|:"87", |136|:"88", |137|:"89", |138|:"8A", |139|:"8B", |140|:"8C", |141|:"8D", |142|:"8E", |143|:"8F", |144|:"90", |145|:"91", |146|:"92", |147|:"93", |148|:"94", |149|:"95", |150|:"96", |151|:"97", |152|:"98", |153|:"99", |154|:"9A", |155|:"9B", |156|:"9C", |157|:"9D", |158|:"9E", |159|:"9F", |160|:"A0", |161|:"A1", |162|:"A2", |163|:"A3", |164|:"A4", |165|:"A5", |166|:"A6", |167|:"A7", |168|:"A8", |169|:"A9", |170|:"AA", |171|:"AB", |172|:"AC", |173|:"AD", |174|:"AE", |175|:"AF", |176|:"B0", |177|:"B1", |178|:"B2", |179|:"B3", |180|:"B4", |181|:"B5", |182|:"B6", |183|:"B7", |184|:"B8", |185|:"B9", |186|:"BA", |187|:"BB", |188|:"BC", |189|:"BD", |190|:"BE", |191|:"BF", |192|:"C0", |193|:"C1", |194|:"C2", |195|:"C3", |196|:"C4", |197|:"C5", |198|:"C6", |199|:"C7", |200|:"C8", |201|:"C9", |202|:"CA", |203|:"CB", |204|:"CC", |205|:"CD", |206|:"CE", |207|:"CF", |208|:"D0", |209|:"D1", |210|:"D2", |211|:"D3", |212|:"D4", |213|:"D5", |214|:"D6", |215|:"D7", |216|:"D8", |217|:"D9", |218|:"DA", |219|:"DB", |220|:"DC", |221|:"DD", |222|:"DE", |223|:"DF", |224|:"E0", |225|:"E1", |226|:"E2", |227|:"E3", |228|:"E4", |229|:"E5", |230|:"E6", |231|:"E7", |232|:"E8", |233|:"E9", |234|:"EA", |235|:"EB", |236|:"EC", |237|:"ED", |238|:"EE", |239|:"EF", |240|:"F0", |241|:"F1", |242|:"F2", |243|:"F3", |244|:"F4", |245|:"F5", |246|:"F6", |247|:"F7", |248|:"F8", |249|:"F9", |250|:"FA", |251|:"FB", |252|:"FC", |253|:"FD", |254|:"FE", |255|:"FF"} as record
  set ocid8Bit2HexDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocid8Bit2HexDict's setDictionary:(record8Bit2Hex)
  set str8BitNum to arg8BitNum as string
  set ocidValue to (ocid8Bit2HexDict's valueForKey:(str8BitNum))
  set strValue to ocidValue as text
return strValue
end getHex

|

px to mm 解像度指定


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
ダイアログ部ベーススクリプト
https://www.macscripter.net/t/edit-db123s-dialog-for-use-with-asobjc/73636/2
*)
#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 framework "Carbon"
use scripting additions
property refMe : a reference to current application


##############################
#####ダイアログ
##############################
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
#####ダイアログ実行
set dialogResult to my doShowDialog()
if dialogResult is missing value then
return "【エラー】キャンセルしました"
end if
set strReturnedTextPX to strOne of dialogResult
set strReturnedTextPPI to strTwo of dialogResult

##############################
#####戻り値整形
##############################
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedTextPX))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
####戻り値を半角にする
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
##カンマ置換
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:(",") withString:(".")
###数字以外の値を取る
#set ocidDecSet to refMe's NSCharacterSet's decimalDigitCharacterSet
#set ocidCharSet to ocidDecSet's invertedSet()
#set ocidCharArray to ocidResponseHalfwidth's componentsSeparatedByCharactersInSet:ocidCharSet
#set ocidInteger to ocidCharArray's componentsJoinedByString:""
###テキストにしてから
set strTextM to ocidTextM as text
###数値に
set strReturnedTextPX to strTextM as integer

###
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedTextPPI))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
####戻り値を半角にする
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
##カンマ置換
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:(",") withString:(".")
###数字以外の値を取る
#set ocidDecSet to refMe's NSCharacterSet's decimalDigitCharacterSet
#set ocidCharSet to ocidDecSet's invertedSet()
#set ocidCharArray to ocidResponseHalfwidth's componentsSeparatedByCharactersInSet:ocidCharSet
#set ocidInteger to ocidCharArray's componentsJoinedByString:""
###テキストにしてから
set strTextM to ocidTextM as text
###数値に
set strReturnedTextPPI to strTextM as number

##############################
#####計算部
##############################
set numVar to 25.4 as number

###そのまま
set numInch to (strReturnedTextPX / strReturnedTextPPI) as number
set numRaw to numVar * numInch as number

set strMes to ("計算結果です:" & strReturnedTextPX & "px →" & numRaw & "mm(" & strReturnedTextPPI & "ppi)  \r") as text
log numRaw
###整数切り捨て
set intDown to (round of (numRaw) rounding down) as integer
log intDown
set strMes to (strMes & "整数切捨:" & intDown & "\r") as text
###整数切り上げ
set intUP to (round of (numRaw) rounding up) as integer
log intUP
set strMes to (strMes & "整数切上:" & intUP & "\r") as text
###切り捨て 小数点2
set num2Dec to ((round of ((numRaw) * 100) rounding down) / 100) as number
log num2Dec
set strMes to (strMes & "小数点2位:" & num2Dec & "\r") as text
###切り捨て 小数点3
set num3Dec to ((round of ((numRaw) * 1000) rounding down) / 1000) as number
log num3Dec
set strMes to (strMes & "小数点3位:" & num3Dec & "\r") as text
###切り捨て 小数点4
set num4Dec to ((round of ((numRaw) * 10000) rounding down) / 10000) as number
log num4Dec
set strMes to (strMes & "小数点4位:" & num4Dec & "\r") as text
####
set strMes to (strMes & "小数点以下計算は切り捨て\r【留意】ピクセル指定時には『整数』が必要です") 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
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias

try
  set recordResult to (display dialog strMes with title strMes default answer numRaw buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) as record
on error
  log "エラーしました"
return "キャンセルしました"
end try
if (gave up of recordResult) is true then
return "時間切れです"
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




####################################
###### ダイアログ
####################################
property appDialogWindow : missing value
property strOneTextField : missing value
property strTwoTextField : missing value
property appCancelButton : missing value
property appOkButton : missing value
property strOne : missing value
property strTwo : missing value
property appOkClicked : false
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

on doShowDialog()
  if refMe's AEInteractWithUser(-1, missing value, missing value) ≠ 0 then
return missing value
  end if
  if refMe's NSThread's isMainThread() then
my doPerformDialog:(missing value)
  else
its performSelectorOnMainThread:("doPerformDialog:") withObject:(missing value) waitUntilDone:true
  end if
  if my appOkClicked then
return {strOne:my strOne as text, strTwo:my strTwo as text}
  end if
return missing value
end doShowDialog

on doPerformDialog:(args)
  set strOneLabel to refMe's NSTextField's labelWithString:("px数:")
strOneLabel's setFrame:(refMe's NSMakeRect(20, 85, 70, 20))
  
  set my strOneTextField to refMe's NSTextField's textFieldWithString:""
strOneTextField's setFrame:(refMe's NSMakeRect(87, 85, 245, 20))
strOneTextField's setEditable:true
strOneTextField's setBordered:true
strOneTextField's setPlaceholderString:("pxサイズ整数")
  
  
  set strTwoLabel to refMe's NSTextField's labelWithString:("ppi(dpi):")
strTwoLabel's setFrame:(refMe's NSMakeRect(20, 55, 70, 20))
  
  set my strTwoTextField to refMe's NSTextField's textFieldWithString:("")
strTwoTextField's setFrame:(refMe's NSMakeRect(87, 55, 245, 20))
strTwoTextField's setEditable:true
strTwoTextField's setBordered:true
strTwoTextField's setPlaceholderString:("ppi解像度")
strTwoTextField's setDelegate:(me)
  set my appCancelButton to refMe's NSButton's buttonWithTitle:"Cancel" target:me action:"doButtonAction:"
appCancelButton's setFrameSize:{94, 32}
appCancelButton's setFrameOrigin:{150, 10}
appCancelButton's setKeyEquivalent:(character id 27)
  
  set my appOkButton to refMe's NSButton's buttonWithTitle:"OK" target:me action:"doButtonAction:"
appOkButton's setFrameSize:{94, 32}
appOkButton's setFrameOrigin:{245, 10}
appOkButton's setKeyEquivalent:return
appOkButton's setEnabled:false
  
  set ocidWindowSize to refMe's NSMakeRect(0, 0, 355, 125)
  set ocidWinStyle to (refMe's NSWindowStyleMaskTitled as integer) + (refMe's NSWindowStyleMaskClosable as integer)
  set my appDialogWindow to refMe's NSWindow's alloc()'s initWithContentRect:(ocidWindowSize) styleMask:(ocidWinStyle) backing:(refMe's NSBackingStoreBuffered) defer:true
  
appDialogWindow's contentView()'s addSubview:(strOneLabel)
appDialogWindow's contentView()'s addSubview:(strOneTextField)
appDialogWindow's contentView()'s addSubview:(strTwoLabel)
appDialogWindow's contentView()'s addSubview:(strTwoTextField)
appDialogWindow's contentView()'s addSubview:(appCancelButton)
appDialogWindow's contentView()'s addSubview:(appOkButton)
  
appDialogWindow's setTitle:"PX→mm(解像度指定)"
appDialogWindow's setLevel:(refMe's NSModalPanelWindowLevel)
appDialogWindow's setDelegate:(me)
appDialogWindow's orderFront:(me)
appDialogWindow's |center|()
  
refMe's NSApp's activateIgnoringOtherApps:true
refMe's NSApp's runModalForWindow:(appDialogWindow)
end doPerformDialog:

on doButtonAction:(sender)
  if sender is my appOkButton then
    set my strOne to strOneTextField's stringValue()
    set my strTwo to strTwoTextField's stringValue()
    set my appOkClicked to true
  end if
my appDialogWindow's |close|()
end doButtonAction:

on controlTextDidChange:(objNotification)
  set sender to objNotification's object()
  if sender is my strTwoTextField then
    if sender's stringValue() as text"" then
my (appOkButton's setEnabled:true)
    else
my (appOkButton's setEnabled:false)
    end if
  end if
end controlTextDidChange:

on windowWillClose:(objNotification)
refMe's NSApp's stopModal()
end windowWillClose:


|

【変換】パーミッション8進→16進


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

#!/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 strTitle to ("3桁8進数を入力") as text

set strMes to "3桁8進数を入力\n777-->0x1ff\n755-->0x1ed\n700-->0x1c0"

########################
## クリップボードの中身取り出し
########################
###初期化
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
  ###値を格納する
  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 "1" as text
  end if
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
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 10 without hidden answer) as record
on error
  log "エラーしました"
return
end try

if "OK" is equal to (button returned of recordResult) then
  set strReturnedText to (text returned of recordResult) as text
else if (gave up of recordResult) is true then
return "時間切れです"
else
return "キャンセル"
end if
##############################
#####戻り値整形
##############################
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
####戻り値を半角にする
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
##カンマ置換
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:(",") withString:(".")
###数字以外の値を取る
#set ocidDecSet to refMe's NSCharacterSet's decimalDigitCharacterSet
#set ocidCharSet to ocidDecSet's invertedSet()
#set ocidCharArray to ocidResponseHalfwidth's componentsSeparatedByCharactersInSet:ocidCharSet
#set ocidInteger to ocidCharArray's componentsJoinedByString:""
###テキストにしてから
set strTextM to ocidTextM as text

##############################
#####計算部
##############################
set strCommandText to ("/bin/echo $(printf \"%#x\" \"$((8#" & strTextM & "))\")") as text
set numRaw to (do shell script strCommandText) 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
try
  set recordResult to (display dialog strMes with title strMes default answer numRaw buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) as record
on error
  log "エラーしました"
end try
if (gave up of recordResult) is true then
return "時間切れです"
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
###################################
#####パーミッション 8進→10進
###################################

to doOct2Dem(argOctNo)
  set strOctalText to argOctNo as text
  set num3Line to first item of strOctalText as number
  set num2Line to 2nd item of strOctalText as number
  set num1Line to last item of strOctalText as number
  set numDecimal to (num3Line * 64) + (num2Line * 8) + (num1Line * 1)
return numDecimal
end doOct2Dem

|

【変換】パーミッション10進→16進


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

#!/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 strTitle to ("3桁10進数を入力") as text

set strMes to "3桁10進数を入力\n511(777)-->0x1ff\n493(755)-->0x1ed\n448(700)-->0x1c0"

########################
## クリップボードの中身取り出し
########################
###初期化
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
  ###値を格納する
  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 "1" as text
  end if
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
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title strTitle default answer strReadString buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 10 without hidden answer) as record
on error
  log "エラーしました"
return
end try

if "OK" is equal to (button returned of recordResult) then
  set strReturnedText to (text returned of recordResult) as text
else if (gave up of recordResult) is true then
return "時間切れです"
else
return "キャンセル"
end if
##############################
#####戻り値整形
##############################
set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedText))
###タブと改行を除去しておく
set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
##改行除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
##タブ除去
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
####戻り値を半角にする
set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
##カンマ置換
set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:(",") withString:(".")
###数字以外の値を取る
#set ocidDecSet to refMe's NSCharacterSet's decimalDigitCharacterSet
#set ocidCharSet to ocidDecSet's invertedSet()
#set ocidCharArray to ocidResponseHalfwidth's componentsSeparatedByCharactersInSet:ocidCharSet
#set ocidInteger to ocidCharArray's componentsJoinedByString:""
###テキストにしてから
set strTextM to ocidTextM as text

##############################
#####計算部
##############################
set strCommandText to ("/bin/echo $(printf \"%#x\" \"" & strTextM & "\")") as text
set numRaw to (do shell script strCommandText) 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
try
  set recordResult to (display dialog strMes with title strMes default answer numRaw buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) as record
on error
  log "エラーしました"
end try
if (gave up of recordResult) is true then
return "時間切れです"
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
###################################
#####パーミッション 8進→10進
###################################

to doOct2Dem(argOctNo)
  set strOctalText to argOctNo as text
  set num3Line to first item of strOctalText as number
  set num2Line to 2nd item of strOctalText as number
  set num1Line to last item of strOctalText as number
  set numDecimal to (num3Line * 64) + (num2Line * 8) + (num1Line * 1)
return numDecimal
end doOct2Dem

|

[単位換算]mmからpxに 解像度指定


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
BaseScript
https://www.macscripter.net/t/edit-db123s-dialog-for-use-with-asobjc/
*)
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use framework "Foundation"
use framework "AppKit"
#use framework "Carbon"
use scripting additions
property refMe : current application


###ダイアログ
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 listRect to doDialoge()
if listRect is false then
return "キャンセルしました"
end if
###戻り値
set strH to (item 2 of listRect) as text
set strW to (item 1 of listRect) as text
set strP to (item 3 of listRect) as text
###戻り値整形
set numH to doText2Integer(strH) as number
set numW to doText2Integer(strW) as number
set numP to doText2Integer(strP) as number

log numH
##############################
#####計算部
##############################
set numVar to 25.4 as number
###
set numRawH to (numH / numVar) as number
set numRawW to (numW / numVar) as number
log numRawH
###
set numPxH to (round of (numRawH * numP) rounding down) as integer
set numPxW to (round of (numRawW * numP) rounding down) as integer
##############################
#####戻り値表示
##############################
set strMes to ("横mm:" & strW & "\n縦mm:" & strH & "\n解像度ppi:" & strP & "の計算結果\n横px:" & numPxW & "\n縦px:" & numPxH & "\n") as text
set strAns to ("width: " & numPxW & "px; height: " & numPxH & "px;") 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/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog (strMes & strAns) with title "計算結果です" default answer strAns buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) as record
on error
  log "エラーしました"
return "エラーしました"
end try
if (gave up of recordResult) is true then
return "時間切れです"
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
##############################
#####戻り値整形
##############################
to doText2Integer(argText)
  set ocidResponseText to (refMe's NSString's stringWithString:(argText))
  ###タブと改行を除去しておく
  set ocidTextM to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
ocidTextM's appendString:(ocidResponseText)
  ##改行除去
  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\n") withString:("")
  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("")
  ##タブ除去
  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
  ####戻り値を半角にする
  set ocidNSStringTransform to (refMe's NSStringTransformFullwidthToHalfwidth)
  set ocidTextM to (ocidTextM's stringByApplyingTransform:ocidNSStringTransform |reverse|:false)
  ##カンマ置換
  set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:(",") withString:(".")
  ###テキストにしてから
  set strTextM to ocidTextM as text
  ###数値にして戻す
return strTextM as number
end doText2Integer


############################
###3段ダイアログ
############################
property appDialogWindow : missing value
property appCancelButton : missing value
property appOkButton : missing value
property appOkClicked : false

property strOneTextField : missing value
property strTwoTextField : missing value
property strThreeTextField : missing value

property strOne : missing value
property strTwo : missing value
property strThree : missing value


to doDialoge()
  set dialogResult to my doShowDialog()
  if dialogResult is missing value then
return false
  end if
  set {strOne, strTwo, strThree} to {strOne, strTwo, strThree} of dialogResult
return {strOne, strTwo, strThree} as list
end doDialoge

on doShowDialog()
  if refMe's AEInteractWithUser(-1, missing value, missing value) ≠ 0 then
return missing value
  end if
  if refMe's NSThread's isMainThread() then
my doPerformDialog:(missing value)
  else
its performSelectorOnMainThread:("doPerformDialog:") withObject:(missing value) waitUntilDone:true
  end if
  if my appOkClicked then
return {strOne:my strOne as text, strTwo:my strTwo as text, strThree:my strThree as text}
  end if
return missing value
end doShowDialog

on doPerformDialog:(args)
  set strOneLabel to refMe's NSTextField's labelWithString:("幅w mm:")
strOneLabel's setFrame:(refMe's NSMakeRect(20, 120, 70, 20))
  
  set my strOneTextField to refMe's NSTextField's textFieldWithString:""
strOneTextField's setFrame:(refMe's NSMakeRect(87, 120, 245, 20))
strOneTextField's setEditable:true
strOneTextField's setBordered:true
strOneTextField's setPlaceholderString:("幅サイズmm数値入力")
  
  
  set strTwoLabel to refMe's NSTextField's labelWithString:("縦h mm:")
strTwoLabel's setFrame:(refMe's NSMakeRect(20, 90, 70, 20))
  
  set my strTwoTextField to refMe's NSTextField's textFieldWithString:("")
strTwoTextField's setFrame:(refMe's NSMakeRect(87, 90, 245, 20))
strTwoTextField's setEditable:true
strTwoTextField's setBordered:true
strTwoTextField's setPlaceholderString:("縦サイズmm入力")
  
  set strThreeLabel to refMe's NSTextField's labelWithString:("解像度ppi:")
strThreeLabel's setFrame:(refMe's NSMakeRect(20, 55, 70, 20))
  
  set my strThreeTextField to refMe's NSTextField's textFieldWithString:("")
strThreeTextField's setFrame:(refMe's NSMakeRect(87, 55, 245, 20))
strThreeTextField's setEditable:true
strThreeTextField's setBordered:true
strThreeTextField's setPlaceholderString:("解像度ppi数値入力")
strThreeTextField's setDelegate:(me)
  
  set my appCancelButton to refMe's NSButton's buttonWithTitle:"Cancel" target:me action:"doButtonAction:"
appCancelButton's setFrameSize:{94, 32}
appCancelButton's setFrameOrigin:{150, 10}
appCancelButton's setKeyEquivalent:(character id 27)
  
  set my appOkButton to refMe's NSButton's buttonWithTitle:"OK" target:me action:"doButtonAction:"
appOkButton's setFrameSize:{94, 32}
appOkButton's setFrameOrigin:{245, 10}
appOkButton's setKeyEquivalent:return
appOkButton's setEnabled:false
  
  set ocidWindowSize to refMe's NSMakeRect(0, 0, 380, 160)
  set ocidWinStyle to (refMe's NSWindowStyleMaskTitled as integer) + (refMe's NSWindowStyleMaskClosable as integer)
  set my appDialogWindow to refMe's NSWindow's alloc()'s initWithContentRect:(ocidWindowSize) styleMask:(ocidWinStyle) backing:(refMe's NSBackingStoreBuffered) defer:true
  
appDialogWindow's contentView()'s addSubview:(strOneLabel)
appDialogWindow's contentView()'s addSubview:(strOneTextField)
  
appDialogWindow's contentView()'s addSubview:(strTwoLabel)
appDialogWindow's contentView()'s addSubview:(strTwoTextField)
  
appDialogWindow's contentView()'s addSubview:(strThreeLabel)
appDialogWindow's contentView()'s addSubview:(strThreeTextField)
  
appDialogWindow's contentView()'s addSubview:(appCancelButton)
appDialogWindow's contentView()'s addSubview:(appOkButton)
  
appDialogWindow's setTitle:"数値換算"
appDialogWindow's setLevel:(refMe's NSModalPanelWindowLevel)
appDialogWindow's setDelegate:(me)
appDialogWindow's orderFront:(me)
appDialogWindow's |center|()
  
refMe's NSApp's activateIgnoringOtherApps:true
refMe's NSApp's runModalForWindow:(appDialogWindow)
end doPerformDialog:

on doButtonAction:(sender)
  if sender is my appOkButton then
    set my strOne to strOneTextField's stringValue()
    set my strTwo to strTwoTextField's stringValue()
    set my strThree to strThreeTextField's stringValue()
    set my appOkClicked to true
  end if
my appDialogWindow's |close|()
end doButtonAction:

on controlTextDidChange:(objNotification)
  set sender to objNotification's object()
  if sender is my strThreeTextField then
    if sender's stringValue() as text"" then
my (appOkButton's setEnabled:true)
    else
my (appOkButton's setEnabled:false)
    end if
  end if
end controlTextDidChange:

on windowWillClose:(objNotification)
refMe's NSApp's stopModal()
end windowWillClose:




|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom