NSDecimalNumber

NSDecimalNumber

#A+B
サンプルコード

サンプルソース(参考)
行番号ソース
001set ANS to A's  decimalNumberByAdding:(B)
AppleScriptで生成しました

#A-B
サンプルコード

サンプルソース(参考)
行番号ソース
001set ANS to A's  decimalNumberBySubtracting:(B)
AppleScriptで生成しました

#A×B
サンプルコード

サンプルソース(参考)
行番号ソース
001set ANS to A's  decimalNumberByMultiplyingBy:(B)
AppleScriptで生成しました

#A➗B
サンプルコード

サンプルソース(参考)
行番号ソース
001set ANS to A's  decimalNumberByDividingBy:(B)
AppleScriptで生成しました

#A^B ベキ算
サンプルコード

サンプルソース(参考)
行番号ソース
001set ANS to A's  decimalNumberByRaisingToPower:(B)
AppleScriptで生成しました

|

IPアドレスを16進数に変換する


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 scripting additions
009
010property refMe : a reference to current application
011
012set strIP to ("124.83.184.252") as text
013
014
015set strDelim to AppleScript's text item delimiters
016set AppleScript's text item delimiters to "."
017set listSeg to every text item of strIP
018set AppleScript's text item delimiters to strDelim
019
020set nun1seg to (item 1 of listSeg) as integer
021set nun2seg to (item 2 of listSeg) as integer
022set nun3seg to (item 3 of listSeg) as integer
023set nun4seg to (item 4 of listSeg) as integer
024
025set ocidSeg1No to refMe's NSNumber's numberWithInt:(nun1seg)
026set ocidSeg2No to refMe's NSNumber's numberWithInt:(nun2seg)
027set ocidSeg3No to refMe's NSNumber's numberWithInt:(nun3seg)
028set ocidSeg4No to refMe's NSNumber's numberWithInt:(nun4seg)
029
030set ocidBeki to refMe's NSDecimalNumber's decimalNumberWithMantissa:2 exponent:0 isNegative:(false)
031
032set ocidSeg1Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun1seg) exponent:0 isNegative:(false)
033set ocidSeg2Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun2seg) exponent:0 isNegative:(false)
034set ocidSeg3Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun3seg) exponent:0 isNegative:(false)
035set ocidSeg4Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun4seg) exponent:0 isNegative:(false)
036
037set ocidSeg1DemBeki to (ocidSeg1Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:24))
038set ocidSeg2DemBeki to (ocidSeg2Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:16))
039set ocidSeg3DemBeki to (ocidSeg3Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:8))
040set ocidSeg4DemBeki to (ocidSeg4Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:0))
041
042set resDem1 to ocidSeg1DemBeki's decimalNumberByAdding:ocidSeg2DemBeki
043set resDem2 to resDem1's decimalNumberByAdding:ocidSeg3DemBeki
044set resDem3 to resDem2's decimalNumberByAdding:ocidSeg4DemBeki
045
046set strDecIP to resDem3's stringValue() as text
047
048
049set strCommandText to ("printf '%X\n' \"" & strDecIP & "\"") as text
050log "\r" & strCommandText & "\r"
051set strExec to ("/bin/zsh -c \"" & strCommandText & "\"")
052try
053  set strResponse to (do shell script strExec) as text
054end try
055set strHex to ("0x" & strResponse) as text
056
057#URLコンポーネント初期化
058set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
059###スキーム を追加
060ocidURLComponents's setScheme:("http")
061###ホストを追加
062ocidURLComponents's setHost:(strHex)
063###パスを追加
064ocidURLComponents's setPath:("/")
065##URLに戻して テキストにしておく
066set ocidOpenURL to ocidURLComponents's |URL|()
067set strURL to ocidOpenURL's absoluteString()
068
069
070##
071set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
072set boolDone to appSharedWorkspace's openURL:(ocidOpenURL)
073
AppleScriptで生成しました

|

IPアドレスを10進数に変換する


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 scripting additions
009
010property refMe : a reference to current application
011
012set strIP to ("124.83.184.252") as text
013
014
015set strDelim to AppleScript's text item delimiters
016set AppleScript's text item delimiters to "."
017set listSeg to every text item of strIP
018set AppleScript's text item delimiters to strDelim
019
020set nun1seg to (item 1 of listSeg) as integer
021set nun2seg to (item 2 of listSeg) as integer
022set nun3seg to (item 3 of listSeg) as integer
023set nun4seg to (item 4 of listSeg) as integer
024
025set ocidSeg1No to refMe's NSNumber's numberWithInt:(nun1seg)
026set ocidSeg2No to refMe's NSNumber's numberWithInt:(nun2seg)
027set ocidSeg3No to refMe's NSNumber's numberWithInt:(nun3seg)
028set ocidSeg4No to refMe's NSNumber's numberWithInt:(nun4seg)
029
030set ocidBeki to refMe's NSDecimalNumber's decimalNumberWithMantissa:2 exponent:0 isNegative:(false)
031
032set ocidSeg1Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun1seg) exponent:0 isNegative:(false)
033set ocidSeg2Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun2seg) exponent:0 isNegative:(false)
034set ocidSeg3Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun3seg) exponent:0 isNegative:(false)
035set ocidSeg4Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun4seg) exponent:0 isNegative:(false)
036
037set ocidSeg1DemBeki to (ocidSeg1Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:24))
038set ocidSeg2DemBeki to (ocidSeg2Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:16))
039set ocidSeg3DemBeki to (ocidSeg3Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:8))
040set ocidSeg4DemBeki to (ocidSeg4Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:0))
041
042set resDem1 to ocidSeg1DemBeki's decimalNumberByAdding:ocidSeg2DemBeki
043set resDem2 to resDem1's decimalNumberByAdding:ocidSeg3DemBeki
044set resDem3 to resDem2's decimalNumberByAdding:ocidSeg4DemBeki
045
046set strDecIP to resDem3's stringValue() as text
047
048
049#URLコンポーネント初期化
050set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
051###スキーム を追加
052ocidURLComponents's setScheme:("http")
053###ホストを追加
054ocidURLComponents's setHost:(strDecIP)
055###パスを追加
056ocidURLComponents's setPath:("/")
057##URLに戻して テキストにしておく
058set ocidOpenURL to ocidURLComponents's |URL|()
059set strURL to ocidOpenURL's absoluteString()
060
061##
062set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
063set boolDone to appSharedWorkspace's openURL:(ocidOpenURL)
064
AppleScriptで生成しました

|

縦横比計算(修正 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で生成しました

|

小数点以下 X桁での丸め


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
006##自分環境がos12なので2.8にしているだけです
007use AppleScript version "2.8"
008use framework "Foundation"
009use scripting additions
010
011property refMe : a reference to current application
012
013set numNumber to (29.970029830933) as number
014
015set ocidDecimalNumber to refMe's NSDecimalNumber's decimalNumberWithString:(numNumber as text)
016set appNumberFormatter to refMe's NSNumberFormatter's alloc()'s init()
017appNumberFormatter's setPositiveFormat:("#,##0.00")
018set ocidDecimalNumber to appNumberFormatter's stringFromNumber:(ocidDecimalNumber)
019
020log ocidDecimalNumber as text
021log ocidDecimalNumber's doubleValue() as number
022-->(*29.97*)
AppleScriptで生成しました

|

[AppleScript]負の数値を整数にする


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002use AppleScript version "2.8"
003use framework "Foundation"
004use framework "AppKit"
005use scripting additions
006
007property refMe : a reference to current application
008
009set numNegative to -320.5 as number
010set strNegative to (numNegative) as text
011set ocidNegativeString to (refMe's NSString's stringWithString:(strNegative))
012set ocidDecimalNegativeNumber to refMe's NSDecimalNumber's decimalNumberWithString:(ocidNegativeString)
013set ocidNegativeOne to refMe's NSDecimalNumber's decimalNumberWithString:("-1")
014set ocidAbsoluteValue to ocidDecimalNegativeNumber's decimalNumberByMultiplyingBy:(ocidNegativeOne)
015log ocidAbsoluteValue's doubleValue() as number
016log ocidAbsoluteValue's floatValue() as number
017log ocidAbsoluteValue's stringValue() as text
018
019
020set numNegative to -320.5 as number
021if numNegative < 0 then
022  set numDouble to (((numNegative as number) ^ 2) ^ 0.5) as number
023end if
024log numDouble
025
026
027set numNegative to -320.5 as number
028if numNegative < 0 then
029  set strNegative to numNegative as text
030  set listNegativeNo to (every character of strNegative) as list
031  set numDouble to (text 2 thru (count of strNegative) of strNegative) as number
032end if
033log numDouble
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で生成しました

|

[四捨五入]小数点以下の桁数(テキストとして扱う)

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

property refMe : a reference to current application

set numDecNo to "123.45678" as text

set ocidDecimalNumber to (refMe's NSDecimalNumber's decimalNumberWithString:numDecNo)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text

###NSNumberFormatterの初期化
set ocidNSNumberFormatter to refMe's NSNumberFormatter's alloc()'s init()
log className() of ocidNSNumberFormatter as text
###小数点以下2桁のフォーマット
(ocidNSNumberFormatter's setPositiveFormat:"##0.00")
####フォーマットを適応
set ocidDecimalNumber to (ocidNSNumberFormatter's stringFromNumber:ocidDecimalNumber)
log ocidDecimalNumber as text
log className() of ocidDecimalNumber as text
log ocidDecimalNumber as text
-->(*123.46*)

|

その他のカテゴリー

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