NSDecimalNumber
#A-B
#A×B
#A➗B
#A^B ベキ算
| 固定リンク
行番号 | ソース |
---|---|
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 | use AppleScript version "2.8" |
007 | use framework "Foundation" |
008 | use scripting additions |
009 | |
010 | property refMe : a reference to current application |
011 | |
012 | set strIP to ("124.83.184.252") as text |
013 | |
014 | |
015 | set strDelim to AppleScript's text item delimiters |
016 | set AppleScript's text item delimiters to "." |
017 | set listSeg to every text item of strIP |
018 | set AppleScript's text item delimiters to strDelim |
019 | |
020 | set nun1seg to (item 1 of listSeg) as integer |
021 | set nun2seg to (item 2 of listSeg) as integer |
022 | set nun3seg to (item 3 of listSeg) as integer |
023 | set nun4seg to (item 4 of listSeg) as integer |
024 | |
025 | set ocidSeg1No to refMe's NSNumber's numberWithInt:(nun1seg) |
026 | set ocidSeg2No to refMe's NSNumber's numberWithInt:(nun2seg) |
027 | set ocidSeg3No to refMe's NSNumber's numberWithInt:(nun3seg) |
028 | set ocidSeg4No to refMe's NSNumber's numberWithInt:(nun4seg) |
029 | |
030 | set ocidBeki to refMe's NSDecimalNumber's decimalNumberWithMantissa:2 exponent:0 isNegative:(false) |
031 | |
032 | set ocidSeg1Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun1seg) exponent:0 isNegative:(false) |
033 | set ocidSeg2Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun2seg) exponent:0 isNegative:(false) |
034 | set ocidSeg3Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun3seg) exponent:0 isNegative:(false) |
035 | set ocidSeg4Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun4seg) exponent:0 isNegative:(false) |
036 | |
037 | set ocidSeg1DemBeki to (ocidSeg1Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:24)) |
038 | set ocidSeg2DemBeki to (ocidSeg2Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:16)) |
039 | set ocidSeg3DemBeki to (ocidSeg3Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:8)) |
040 | set ocidSeg4DemBeki to (ocidSeg4Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:0)) |
041 | |
042 | set resDem1 to ocidSeg1DemBeki's decimalNumberByAdding:ocidSeg2DemBeki |
043 | set resDem2 to resDem1's decimalNumberByAdding:ocidSeg3DemBeki |
044 | set resDem3 to resDem2's decimalNumberByAdding:ocidSeg4DemBeki |
045 | |
046 | set strDecIP to resDem3's stringValue() as text |
047 | |
048 | |
049 | set strCommandText to ("printf '%X\n' \"" & strDecIP & "\"") as text |
050 | log "\r" & strCommandText & "\r" |
051 | set strExec to ("/bin/zsh -c \"" & strCommandText & "\"") |
052 | try |
053 | set strResponse to (do shell script strExec) as text |
054 | end try |
055 | set strHex to ("0x" & strResponse) as text |
056 | |
057 | #URLコンポーネント初期化 |
058 | set ocidURLComponents to refMe's NSURLComponents's alloc()'s init() |
059 | ###スキーム を追加 |
060 | ocidURLComponents's setScheme:("http") |
061 | ###ホストを追加 |
062 | ocidURLComponents's setHost:(strHex) |
063 | ###パスを追加 |
064 | ocidURLComponents's setPath:("/") |
065 | ##URLに戻して テキストにしておく |
066 | set ocidOpenURL to ocidURLComponents's |URL|() |
067 | set strURL to ocidOpenURL's absoluteString() |
068 | |
069 | |
070 | ## |
071 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
072 | set boolDone to appSharedWorkspace's openURL:(ocidOpenURL) |
073 | |
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 | use AppleScript version "2.8" |
007 | use framework "Foundation" |
008 | use scripting additions |
009 | |
010 | property refMe : a reference to current application |
011 | |
012 | set strIP to ("124.83.184.252") as text |
013 | |
014 | |
015 | set strDelim to AppleScript's text item delimiters |
016 | set AppleScript's text item delimiters to "." |
017 | set listSeg to every text item of strIP |
018 | set AppleScript's text item delimiters to strDelim |
019 | |
020 | set nun1seg to (item 1 of listSeg) as integer |
021 | set nun2seg to (item 2 of listSeg) as integer |
022 | set nun3seg to (item 3 of listSeg) as integer |
023 | set nun4seg to (item 4 of listSeg) as integer |
024 | |
025 | set ocidSeg1No to refMe's NSNumber's numberWithInt:(nun1seg) |
026 | set ocidSeg2No to refMe's NSNumber's numberWithInt:(nun2seg) |
027 | set ocidSeg3No to refMe's NSNumber's numberWithInt:(nun3seg) |
028 | set ocidSeg4No to refMe's NSNumber's numberWithInt:(nun4seg) |
029 | |
030 | set ocidBeki to refMe's NSDecimalNumber's decimalNumberWithMantissa:2 exponent:0 isNegative:(false) |
031 | |
032 | set ocidSeg1Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun1seg) exponent:0 isNegative:(false) |
033 | set ocidSeg2Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun2seg) exponent:0 isNegative:(false) |
034 | set ocidSeg3Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun3seg) exponent:0 isNegative:(false) |
035 | set ocidSeg4Dem to refMe's NSDecimalNumber's decimalNumberWithMantissa:(nun4seg) exponent:0 isNegative:(false) |
036 | |
037 | set ocidSeg1DemBeki to (ocidSeg1Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:24)) |
038 | set ocidSeg2DemBeki to (ocidSeg2Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:16)) |
039 | set ocidSeg3DemBeki to (ocidSeg3Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:8)) |
040 | set ocidSeg4DemBeki to (ocidSeg4Dem's decimalNumberByMultiplyingBy:(ocidBeki's decimalNumberByRaisingToPower:0)) |
041 | |
042 | set resDem1 to ocidSeg1DemBeki's decimalNumberByAdding:ocidSeg2DemBeki |
043 | set resDem2 to resDem1's decimalNumberByAdding:ocidSeg3DemBeki |
044 | set resDem3 to resDem2's decimalNumberByAdding:ocidSeg4DemBeki |
045 | |
046 | set strDecIP to resDem3's stringValue() as text |
047 | |
048 | |
049 | #URLコンポーネント初期化 |
050 | set ocidURLComponents to refMe's NSURLComponents's alloc()'s init() |
051 | ###スキーム を追加 |
052 | ocidURLComponents's setScheme:("http") |
053 | ###ホストを追加 |
054 | ocidURLComponents's setHost:(strDecIP) |
055 | ###パスを追加 |
056 | ocidURLComponents's setPath:("/") |
057 | ##URLに戻して テキストにしておく |
058 | set ocidOpenURL to ocidURLComponents's |URL|() |
059 | set strURL to ocidOpenURL's absoluteString() |
060 | |
061 | ## |
062 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
063 | set boolDone to appSharedWorkspace's openURL:(ocidOpenURL) |
064 | |
AppleScriptで生成しました |
| 固定リンク
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | (* |
005 | ダイアログ部ベーススクリプト |
006 | https://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 |
010 | use AppleScript version "2.8" |
011 | use framework "Foundation" |
012 | use framework "UniformTypeIdentifiers" |
013 | use framework "AppKit" |
014 | #use framework "Carbon" |
015 | use scripting additions |
016 | property refMe : a reference to current application |
017 | |
018 | doDialoge() |
019 | |
020 | ##################### |
021 | ### |
022 | property appDialogWindow : missing value |
023 | property strOneTextField : missing value |
024 | property strTwoTextField : missing value |
025 | property appCancelButton : missing value |
026 | property appOkButton : missing value |
027 | property strOne : missing value |
028 | property strTwo : missing value |
029 | property appOkClicked : false |
030 | property refNSNotFound : a reference to 9.22337203685477E+18 + 5807 |
031 | |
032 | |
033 | to 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 |
195 | end doDialoge |
196 | |
197 | |
198 | |
199 | #################################### |
200 | ###### ダイアログ |
201 | #################################### |
202 | |
203 | on 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 |
216 | end doShowDialog |
217 | |
218 | on 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) |
268 | end doPerformDialog: |
269 | |
270 | on 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|() |
277 | end doButtonAction: |
278 | |
279 | on 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 |
288 | end controlTextDidChange: |
289 | |
290 | on windowWillClose:(objNotification) |
291 | refMe's NSApp's stopModal() |
292 | end windowWillClose: |
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にしているだけです |
007 | use AppleScript version "2.8" |
008 | use framework "Foundation" |
009 | use scripting additions |
010 | |
011 | property refMe : a reference to current application |
012 | |
013 | set numNumber to (29.970029830933) as number |
014 | |
015 | set ocidDecimalNumber to refMe's NSDecimalNumber's decimalNumberWithString:(numNumber as text) |
016 | set appNumberFormatter to refMe's NSNumberFormatter's alloc()'s init() |
017 | appNumberFormatter's setPositiveFormat:("#,##0.00") |
018 | set ocidDecimalNumber to appNumberFormatter's stringFromNumber:(ocidDecimalNumber) |
019 | |
020 | log ocidDecimalNumber as text |
021 | log ocidDecimalNumber's doubleValue() as number |
022 | -->(*29.97*) |
AppleScriptで生成しました |
| 固定リンク
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | use AppleScript version "2.8" |
003 | use framework "Foundation" |
004 | use framework "AppKit" |
005 | use scripting additions |
006 | |
007 | property refMe : a reference to current application |
008 | |
009 | set numNegative to -320.5 as number |
010 | set strNegative to (numNegative) as text |
011 | set ocidNegativeString to (refMe's NSString's stringWithString:(strNegative)) |
012 | set ocidDecimalNegativeNumber to refMe's NSDecimalNumber's decimalNumberWithString:(ocidNegativeString) |
013 | set ocidNegativeOne to refMe's NSDecimalNumber's decimalNumberWithString:("-1") |
014 | set ocidAbsoluteValue to ocidDecimalNegativeNumber's decimalNumberByMultiplyingBy:(ocidNegativeOne) |
015 | log ocidAbsoluteValue's doubleValue() as number |
016 | log ocidAbsoluteValue's floatValue() as number |
017 | log ocidAbsoluteValue's stringValue() as text |
018 | |
019 | |
020 | set numNegative to -320.5 as number |
021 | if numNegative < 0 then |
022 | set numDouble to (((numNegative as number) ^ 2) ^ 0.5) as number |
023 | end if |
024 | log numDouble |
025 | |
026 | |
027 | set numNegative to -320.5 as number |
028 | if 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 |
032 | end if |
033 | log numDouble |
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 |
008 | use AppleScript version "2.8" |
009 | use framework "Foundation" |
010 | use framework "AppKit" |
011 | use scripting additions |
012 | |
013 | property refMe : a reference to current application |
014 | |
015 | set strPt to doConversionMM2PT(30) |
016 | log 30 & "mmは" |
017 | log strPt & "ptは" |
018 | return strPt |
019 | |
020 | |
021 | ############################ |
022 | # mmをPTに換算 |
023 | ############################ |
024 | to 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 | |
045 | end doConversionMM2PT |
046 | |
047 | |
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 | use AppleScript version "2.6" |
007 | use framework "Foundation" |
008 | use framework "AppKit" |
009 | use scripting additions |
010 | |
011 | property refMe : a reference to current application |
012 | |
013 | |
014 | |
015 | set listInput to {{72, 144}, {288, 360}} as list |
016 | |
017 | log doNestListToCSV(listInput) as text |
018 | |
019 | |
020 | ##################################### |
021 | #【1】PT{{x,y},{w,h}}をMMテキストの"x,y,w,h" |
022 | ##################################### |
023 | to 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 |
031 | end doNestListToCSV |
032 | |
033 | ##################################### |
034 | #【2】リスト{x,y,w,h}をテキストの"x,y,w,h"に |
035 | ##################################### |
036 | to 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 |
041 | end doListToCSV |
042 | |
043 | ##################################### |
044 | #【3】 {{x,y},{w,h}} を{x,y,w,h}のリストに |
045 | ##################################### |
046 | to 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 |
054 | end doDisChildArray |
055 | |
056 | |
057 | ##################################### |
058 | #【4】PT {x,y,w,h}をMM{x,y,w,h}のリストに |
059 | ##################################### |
060 | to 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 |
067 | end doLitPtToListMM |
068 | |
069 | ############################## |
070 | #PT to MM 小数点以下2位まで |
071 | ############################## |
072 | to 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 |
090 | end doPtToMm |
091 | |
092 | |
093 | |
AppleScriptで生成しました |
| 固定リンク
| 固定リンク
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