AppleScript Unit Conversion

単位換算 詰め合わせ 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:




|

2つの値の比率を求める


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

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

doDialoge()

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


to doDialoge()
  
  ##############################
  #####ダイアログ
  ##############################
  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 strReturnedTextX to strOne of dialogResult
  set strReturnedTextY to strTwo of dialogResult
  
  ##############################
  #####戻り値整形
  ##############################
  set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedTextX))
  ###タブと改行を除去しておく
  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 strReturnedTextX to strTextM as number
  
  ###
  set ocidResponseText to (refMe's NSString's stringWithString:(strReturnedTextY))
  ###タブと改行を除去しておく
  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 strReturnedTextY to strTextM as number
  
  ##############################
  #####計算部
  ##############################
  
  
  ###そのまま
  set numRaw to (strReturnedTextX / strReturnedTextY) as number
  set numRaw to (strReturnedTextY / strReturnedTextX) as number
  set strMes to ("計算結果です:" & numRaw & " \r") as text
  
  ###整数切り捨て
  set intDown to ((round of ((numRaw) * 1000) rounding down) / 1000) * 100 as number
  log intDown
  set strMes to (strMes & "パーセント:" & intDown & "% \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 {"クリップボードにコピー", "もう一度", "終了"} default button "もう一度" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
  on error
    log "エラーしました"
return
  end try
  log recordResult
  if button returned of recordResult is "もう一度" then
doDialoge()
  else 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
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}
  end if
return missing value
end doShowDialog

on doPerformDialog:(args)
  set strOneLabel to refMe's NSTextField's labelWithString:("X size:")
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:("X数値のみ")
strOneTextField's setDelegate:(me)
  
  set strTwoLabel to refMe's NSTextField's labelWithString:("Y size:")
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:("Y数値のみ")
  
  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:"比率換算"
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 strOneTextField 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:


|

単位換算 まとめ

詰め合わせ 再実行対応版

ダウンロード - unitcnv.zip

過去版

ダウンロード - 単位換算.zip

|

横サイズから縦サイズ(画像縦横比)

こんな感じの出力をHTMLに書き出します
単位換算 Aspect Ratio
代表的な呼称縦横比
01:SXGA5x412801024
02:XGA4x31280960
03:QWUXGA16x101280800
04:WQHD16x91280720
05:Cinema256x1351280675

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

#!/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 strMes to ("横サイズを入力") as text

########################
## クリップボードの中身取り出し
########################
###初期化
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 "入力してください" 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 strResponse to strTextM as number


##############################
#####HTML部
##############################
###スタイル
set strStylle to "<style>html {font-family: \"Osaka-Mono\",monospace;font-size: 24px;} #bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 580px;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 3px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[単位換算] Aspect Ratio</title>" & strStylle & "</head><body>"
###最後
set strHtmlEndBody to "</body></html>"

###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####bodyまでを追加
(ocidHTMLString's appendString:(strHead))
###テーブルの開始部
set strHTML to ("<div id=\"bordertable\"><table><caption>単位換算 Aspect Ratio</caption>") as text
set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"代表的な呼称\" scope=\"row\" >代表的な呼称</th><th title=\"Aspect Ratio\">縦横比</th><th title=\"\" scope=\"col\">横</th><th title=\"\" scope=\"col\">縦</th></tr></thead><tbody title=\"縦横比の表\" >") as text
##############################
#####計算部
##############################
##項目を増やす場合はこのレコードを増やせばOK
set recordAspectRatio to {|01:SXGA|:{5, 4}, |02:XGA|:{4, 3}, |03:QWUXGA|:{16, 10}, |04:WQHD|:{16, 9}, |05:Cinema|:{256, 135}} as record
set ocidAspectRatioDict to refMe's NSDictionary's alloc()'s initWithDictionary:(recordAspectRatio)
set ocidAllKeys to ocidAspectRatioDict's allKeys()
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:"localizedStandardCompare:"
set ocidAllKeys to ocidAllKeys's sortedArrayUsingDescriptors:({ocidDescriptor})

repeat with itemAllKeys in ocidAllKeys
  set strAllKeys to itemAllKeys as text
  log strAllKeys
  set ocidAspectRatioArray to (ocidAspectRatioDict's objectForKey:(itemAllKeys))
  ###指数取り出し
  set numRatioW to (ocidAspectRatioArray's firstObject()) as integer
  set numRatioH to (ocidAspectRatioArray's lastObject()) as integer
  
  set numRealH to ((strResponse * numRatioH) / numRatioW) as integer
  # log numRealW
  set strAspectRatio to (numRatioW & "x" & numRatioH) as text
  set strHTML to (strHTML & "<tr><td title=\"代表的な呼称\">" & strAllKeys & "</td><td title=\"Aspect Ratio\">" & strAspectRatio & "</td><td title=\"\">" & strResponse & "</td><td title=\"\">" & numRealH & "</td></tr>") as text
end repeat

set strHTML to (strHTML & "</tbody><tfoot></tfoot></table></div>") as text
####テーブルまでを追加
(ocidHTMLString's appendString:(strHTML))
####終了部を追加
(ocidHTMLString's appendString:(strHtmlEndBody))
##############################
#####出力部
##############################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
###
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)

###保存パス
set strFileName to "W2H.html" as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
####
###ファイルに書き出し
set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####テキストエディタで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias

tell application "TextEdit"
  activate
  open file aliasFilePath
end tell




|

縦サイズから横サイズ(画像縦横比)

こんな感じの出力をHTMLに書き出します
単位換算 Aspect Ratio
代表的な呼称縦横比
01:SXGA5x416001280
02:XGA4x317071280
03:QWUXGA16x1020481280
04:WQHD16x922761280
05:Cinema256x13524271280

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

#!/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 strMes to ("縦サイズを入力") as text

########################
## クリップボードの中身取り出し
########################
###初期化
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 "入力してください" 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 strResponse to strTextM as number


##############################
#####HTML部
##############################
###スタイル
set strStylle to "<style>html {font-family: \"Osaka-Mono\",monospace;font-size: 24px;} #bordertable {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} #bordertable table { width: 580px;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} #bordertable caption { font-weight: 900;} #bordertable thead { font-weight: 600;border-spacing:0px;} #bordertable td {border: solid 1px #666666;padding: 3px;margin: 0px;word-wrap: break-word;border-spacing:0px;} #bordertable tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} #bordertable th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>"
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>[単位換算] Aspect Ratio</title>" & strStylle & "</head><body>"
###最後
set strHtmlEndBody to "</body></html>"

###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####bodyまでを追加
(ocidHTMLString's appendString:(strHead))
###テーブルの開始部
set strHTML to ("<div id=\"bordertable\"><table><caption>単位換算 Aspect Ratio</caption>") as text
set strHTML to (strHTML & "<thead title=\"項目名称\"><tr><th title=\"代表的な呼称\" scope=\"row\" >代表的な呼称</th><th title=\"Aspect Ratio\">縦横比</th><th title=\"\" scope=\"col\">横</th><th title=\"\" scope=\"col\">縦</th></tr></thead><tbody title=\"縦横比の表\" >") as text
##############################
#####計算部
##############################
##項目を増やす場合はこのレコードを増やせばOK
set recordAspectRatio to {|01:SXGA|:{5, 4}, |02:XGA|:{4, 3}, |03:QWUXGA|:{16, 10}, |04:WQHD|:{16, 9}, |05:Cinema|:{256, 135}} as record
set ocidAspectRatioDict to refMe's NSDictionary's alloc()'s initWithDictionary:(recordAspectRatio)
set ocidAllKeys to ocidAspectRatioDict's allKeys()
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:"localizedStandardCompare:"
set ocidAllKeys to ocidAllKeys's sortedArrayUsingDescriptors:({ocidDescriptor})

repeat with itemAllKeys in ocidAllKeys
  set strAllKeys to itemAllKeys as text
  log strAllKeys
  set ocidAspectRatioArray to (ocidAspectRatioDict's objectForKey:(itemAllKeys))
  ###指数取り出し
  set numRatioW to (ocidAspectRatioArray's firstObject()) as integer
  set numRatioH to (ocidAspectRatioArray's lastObject()) as integer
  set numRealW to ((strResponse * numRatioW) / numRatioH) as integer
  # log numRealW
  set strAspectRatio to (numRatioW & "x" & numRatioH) as text
  set strHTML to (strHTML & "<tr><td title=\"代表的な呼称\">" & strAllKeys & "</td><td title=\"Aspect Ratio\">" & strAspectRatio & "</td><td title=\"\">" & numRealW & "</td><td title=\"\">" & strResponse & "</td></tr>") as text
end repeat

set strHTML to (strHTML & "</tbody><tfoot></tfoot></table></div>") as text
####テーブルまでを追加
(ocidHTMLString's appendString:(strHTML))
####終了部を追加
(ocidHTMLString's appendString:(strHtmlEndBody))
##############################
#####出力部
##############################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
###
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)

###保存パス
set strFileName to "H2W.html" as text
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
####
###ファイルに書き出し
set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####テキストエディタで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias

tell application "TextEdit"
  activate
  open file aliasFilePath
end tell




|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom