AppleScript record

[Keynote]用紙サイズ指定で新規ドキュメントを作成する

縦型

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


set recordPageSizePt to {|Letter|:{612, 792}, |Legal|:{612, 1008}, |Executive|:{522, 756}, |Ledger|:{1224, 792}, |Tabloid|:{792, 1224}, |Screen|:{468, 373}, |AnsiC|:{1224, 1584}, |AnsiD|:{1584, 2448}, |AnsiE|:{2448, 3168}, |AnsiF|:{2016, 2880}, |ARCHA|:{648, 864}, |ARCHB|:{864, 1296}, |ARCHC|:{1296, 1728}, |ARCHD|:{1728, 2592}, |ARCHE|:{2592, 3456}, |ARCHE1|:{2160, 3024}, |ARCHE2|:{1872, 2736}, |ARCHE3|:{1944, 2808}, |A5|:{420, 595.22}, |A4|:{595.22, 842}, |A3|:{842, 1191}, |A2|:{1191, 1684}, |A1|:{1684, 2384}, |A0|:{2384, 3370}, |A4Extra|:{667, 914}, |A3Extra|:{913, 1262}, |OversizeA2|:{1361, 1772}, |OversizeA1|:{1772, 2551}, |OversizeA0|:{2551, 3529}, |ISOB5|:{499, 709}, |ISOB4|:{709, 1001}, |ISOB2|:{1417, 2004}, |ISOB1|:{2004, 2835}, |C5|:{459, 649}, |JISB5|:{516, 729}, |JISB4|:{729, 1032}, |JISB3|:{1032, 1460}, |JISB2|:{1460, 2064}, |JISB1|:{2064, 2920}, |JISB0|:{2920, 4127}, |Oversize92|:{6624, 6624}, |Slide7.5x10|:{540, 720}} as record
#
set ocidPageSizePtDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidPageSizePtDict's setDictionary:(recordPageSizePt)
set ocidAllKeys to ocidPageSizePtDict's allKeys()
#
set ocidPageNameArray to refMe's NSMutableArray's arrayWithArray:(ocidAllKeys)
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(yes) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
set ocidPaperNameArray to ocidPageNameArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
set listPaperSizeName to ocidPaperNameArray as list
###ダイアログ
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
try
  set listResponse to (choose from list listPaperSizeName with title "選んでください" with prompt "用紙を選んでください" default items (item 1 of listPaperSizeName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strResponse to (item 1 of listResponse) as text

#####
set listPaperSizePt to ocidPageSizePtDict's valueForKey:(strResponse)
log listPaperSizePt as list
set intWidthPt to (item 1 of listPaperSizePt) as number
set intHeightPt to (item 2 of listPaperSizePt) as number
#
# set numVar to 25.4 as number
# set numWidthMM to ((intWidthPt / 72) * numVar) as number
# set numHeightMM to ((intHeightPt / 72) * numVar) as number
##

#####キーノートで新規書類を作成する
tell application "Keynote"
activate
  set objNewDocument to (make new document with properties {name:"" & strResponse & "", height:"" & intHeightPt & "", width:"" & intWidthPt & "", slide numbers showing:true, document theme:theme id "Application/21_BasicWhite/Standard"})
end tell


横型

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


set recordPageSizePt to {|Letter|:{612, 792}, |Legal|:{612, 1008}, |Executive|:{522, 756}, |Ledger|:{1224, 792}, |Tabloid|:{792, 1224}, |Screen|:{468, 373}, |AnsiC|:{1224, 1584}, |AnsiD|:{1584, 2448}, |AnsiE|:{2448, 3168}, |AnsiF|:{2016, 2880}, |ARCHA|:{648, 864}, |ARCHB|:{864, 1296}, |ARCHC|:{1296, 1728}, |ARCHD|:{1728, 2592}, |ARCHE|:{2592, 3456}, |ARCHE1|:{2160, 3024}, |ARCHE2|:{1872, 2736}, |ARCHE3|:{1944, 2808}, |A5|:{420, 595.22}, |A4|:{595.22, 842}, |A3|:{842, 1191}, |A2|:{1191, 1684}, |A1|:{1684, 2384}, |A0|:{2384, 3370}, |A4Extra|:{667, 914}, |A3Extra|:{913, 1262}, |OversizeA2|:{1361, 1772}, |OversizeA1|:{1772, 2551}, |OversizeA0|:{2551, 3529}, |ISOB5|:{499, 709}, |ISOB4|:{709, 1001}, |ISOB2|:{1417, 2004}, |ISOB1|:{2004, 2835}, |C5|:{459, 649}, |JISB5|:{516, 729}, |JISB4|:{729, 1032}, |JISB3|:{1032, 1460}, |JISB2|:{1460, 2064}, |JISB1|:{2064, 2920}, |JISB0|:{2920, 4127}, |Oversize92|:{6624, 6624}, |Slide7.5x10|:{540, 720}} as record
#
set ocidPageSizePtDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidPageSizePtDict's setDictionary:(recordPageSizePt)
set ocidAllKeys to ocidPageSizePtDict's allKeys()
#
set ocidPageNameArray to refMe's NSMutableArray's arrayWithArray:(ocidAllKeys)
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(yes) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
set ocidPaperNameArray to ocidPageNameArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
set listPaperSizeName to ocidPaperNameArray as list
###ダイアログ
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
try
  set listResponse to (choose from list listPaperSizeName with title "選んでください" with prompt "用紙を選んでください" default items (item 1 of listPaperSizeName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strResponse to (item 1 of listResponse) as text

#####
set listPaperSizePt to ocidPageSizePtDict's valueForKey:(strResponse)
log listPaperSizePt as list
set intWidthPt to (item 2 of listPaperSizePt) as number
set intHeightPt to (item 1 of listPaperSizePt) as number
#
# set numVar to 25.4 as number
# set numWidthMM to ((intWidthPt / 72) * numVar) as number
# set numHeightMM to ((intHeightPt / 72) * numVar) as number
##

#####キーノートで新規書類を作成する
tell application "Keynote"
activate
  set objNewDocument to (make new document with properties {name:"" & strResponse & "", height:"" & intHeightPt & "", width:"" & intWidthPt & "", slide numbers showing:true, document theme:theme id "Application/21_BasicWhite/Standard"})
end tell


|

[record] キーと値を入れ替えたレコードを作成する


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

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

##
set recordChooser to {|宗谷地方|:"011000", |留萌地方|:"012000", |石狩地方|:"016000", |網走地方|:"013000", |釧路地方|:"014100", |日高地方|:"015000", |檜山地方|:"017000", |青森県|:"020000", |秋田県|:"050000", |岩手県|:"030000", |宮城県|:"040000", |山形県|:"060000", |福島県|:"070000", |茨城県|:"080000", |栃木県|:"090000", |群馬県|:"100000", |埼玉県|:"110000", |東京都|:"130000", |千葉県|:"120000", |神奈川県|:"140000", |長野県|:"200000", |山梨県|:"190000", |静岡県|:"220000", |愛知県|:"230000", |岐阜県|:"210000", |三重県|:"240000", |新潟県|:"150000", |富山県|:"160000", |石川県|:"170000", |福井県|:"180000", |滋賀県|:"250000", |京都府|:"260000", |大阪府|:"270000", |兵庫県|:"280000", |奈良県|:"290000", |和歌山県|:"300000", |岡山県|:"330000", |広島県|:"340000", |島根県|:"320000", |鳥取県|:"310000", |徳島県|:"360000", |香川県|:"370000", |愛媛県|:"380000", |高知県|:"390000", |山口県|:"350000", |福岡県|:"400000", |大分県|:"440000", |長崎県|:"420000", |佐賀県|:"410000", |熊本県|:"430000", |宮崎県|:"450000", |鹿児島県|:"460100", |奄美|:"460040", |沖縄|:"471000", |大東島|:"472000", |宮古島|:"473000", |八重山|:"474000"} as record
##
set ocidOfficeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidOfficeDict's setDictionary:(recordChooser)
##値=この場合オフィス番号のリストを番号順にソートしておく
set ocidOfficeNoArray to ocidOfficeDict's allValues()
set ocidOfficeNoArrayM to refMe's NSMutableArray's arrayWithArray:(ocidOfficeNoArray)
set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(yes) selector:("localizedStandardCompare:")
set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
set ocidSortedOfficeNoArray to ocidOfficeNoArrayM's sortedArrayUsingDescriptors:(ocidDescriptorArray)
set listOffceNo to ocidSortedOfficeNoArray as list
#キー=この場合オフィス名のリストから キーと値が逆にセットされたレコードを作成
set ocidOfficeReversedDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set ocidOfficeNameArray to ocidOfficeDict's allKeys()
repeat with itemOfficeNameArray in ocidOfficeNameArray
  set ocidValue to (ocidOfficeDict's valueForKey:(itemOfficeNameArray))
(ocidOfficeReversedDict's setValue:(itemOfficeNameArray) forKey:(ocidValue))
end repeat
#ソートされたオフィス番号順のオフィス名リストを作成する
set listOfficeName to {} as list
repeat with itemListOfficeNo in listOffceNo
  set ocidOfficeName to (ocidOfficeReversedDict's valueForKey:(itemListOfficeNo))
  set strOfficeName to ocidOfficeName as text
  set end of listOfficeName to strOfficeName
end repeat

##ここまでの処理で作成されたのがこちら
(*

set recordOfficeReversedDict to {|017000|:"檜山地方", |070000|:"福島県", |140000|:"神奈川県", |210000|:"岐阜県", |390000|:"高知県", |011000|:"宗谷地方", |050000|:"秋田県", |120000|:"千葉県", |370000|:"香川県", |440000|:"大分県", |472000|:"大東島", |014100|:"釧路地方", |460040|:"奄美", |030000|:"岩手県", |016000|:"石狩地方", |100000|:"群馬県", |280000|:"兵庫県", |350000|:"山口県", |420000|:"長崎県", |190000|:"山梨県", |260000|:"京都府", |471000|:"沖縄", |330000|:"岡山県", |400000|:"福岡県", |015000|:"日高地方", |170000|:"石川県", |310000|:"鳥取県", |240000|:"三重県", |220000|:"静岡県", |080000|:"茨城県", |150000|:"新潟県", |130000|:"東京都", |200000|:"長野県", |060000|:"山形県", |380000|:"愛媛県", |450000|:"宮崎県", |460100|:"鹿児島県", |110000|:"埼玉県", |040000|:"宮城県", |360000|:"徳島県", |430000|:"熊本県", |290000|:"奈良県", |013000|:"網走地方", |020000|:"青森県", |340000|:"広島県", |410000|:"佐賀県", |474000|:"八重山", |270000|:"大阪府", |320000|:"島根県", |180000|:"福井県", |250000|:"滋賀県", |012000|:"留萌地方", |300000|:"和歌山県", |090000|:"栃木県", |160000|:"富山県", |473000|:"宮古島", |230000|:"愛知県"} as record

set listOfficeName to {"宗谷地方", "留萌地方", "網走地方", "釧路地方", "日高地方", "石狩地方", "檜山地方", "青森県", "岩手県", "宮城県", "秋田県", "山形県", "福島県", "茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県", "新潟県", "富山県", "石川県", "福井県", "山梨県", "長野県", "岐阜県", "静岡県", "愛知県", "三重県", "滋賀県", "京都府", "大阪府", "兵庫県", "奈良県", "和歌山県", "鳥取県", "島根県", "岡山県", "広島県", "山口県", "徳島県", "香川県", "愛媛県", "高知県", "福岡県", "佐賀県", "長崎県", "熊本県", "大分県", "宮崎県", "奄美", "鹿児島県", "沖縄", "大東島", "宮古島", "八重山"} as list

set listOffceNo to {"011000", "012000", "013000", "014100", "015000", "016000", "017000", "020000", "030000", "040000", "050000", "060000", "070000", "080000", "090000", "100000", "110000", "120000", "130000", "140000", "150000", "160000", "170000", "180000", "190000", "200000", "210000", "220000", "230000", "240000", "250000", "260000", "270000", "280000", "290000", "300000", "310000", "320000", "330000", "340000", "350000", "360000", "370000", "380000", "390000", "400000", "410000", "420000", "430000", "440000", "450000", "460040", "460100", "471000", "472000", "473000", "474000"} as list
*)

|

[setDictionary]レコードをDictionaryにしてキーallKeysをリストに(キー名称日本語)


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

#!/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.6"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()

###アイコンファイル名のレコード
set recordIcon to {|アクア|:"aqua.icns", |ブルー|:"blue.icns", |ダークブルー|:"darkblue.icns", |デフォルト|:"generic.icns", |グレー|:"gray.icns", |グリーン|:"green.icns", |オレンジ|:"orange.icns", |ピンク|:"pink.icns", |レッド|:"red.icns", |グラデーション|:"syft.icns", |バイオレット|:"violet.icns", |ホワイト|:"white.icns", |イエロー|:"yellow.icns"} as record
##可変レコード
set ocidIconDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
##レコードセット
ocidIconDict's setDictionary:(recordIcon)
##キーリスト
set ocidAllKeys to ocidIconDict's allKeys()
##ダイアログ用にリストに
set listAllKeys to ocidAllKeys as list
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###ダイアログ
try
  set listResponse to (choose from list listAllKeys with title "選んでください" with prompt "アイコンを選んでください" default items (item 8 of listAllKeys) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed)
on error
  log "エラーしました"
return "エラーしました"
end try
if listResponse is false then
return "キャンセルしました"
end if
set strResponse to (item 1 of listResponse) as text
###アイコンのファイル名
set ocidIconFileName to (ocidIconDict's valueForKey:(strResponse))
return ocidIconFileName as text



|

[record]新規の空のレコード

普通のテキストキーの場合

set recordBlank to {} as record

set strTmpKey to "tmpKey" as text
set strTemValue to "日本語のVALUE" as text

set recordAddTemp to recordBlank & (run script "return {" & strTmpKey & ":\"" & strTemValue & "\"}") as record

log recordAddTemp
--> {tmpKey:"日本語のVALUE"}
(*tmpKey:日本語のVALUE*)

数値がキーの場合
set recordBlank to {} as record

set numTmpKey to 999999 as integer
set strTemValue to "日本語のVALUE" as text

set recordAddTemp to recordBlank & (run script "return {|" & numTmpKey & "|:\"" & strTemValue & "\"}") as record

log recordAddTemp
--> {|999999|:"日本語のVALUE"}
(*999999:日本語のVALUE*)




########################

set keyRecord to "keyName1"

set valueRecord to "車寅次郎"


set recordNew to (run script "return {" & keyRecord & ":\"" & valueRecord & "\"}") as record


log recordNew

--> (*keyItem:車寅次郎*)

log class of recordNew

--> (*record*)


########################

set keyRecord to "keyName2"

set valueRecord to "車さくら"


set recordAddNew to (run script "return {" & keyRecord & ":\"" & valueRecord & "\"}") as record


set recordNew to recordNew & recordAddNew as record

log recordNew

-->(*keyItem:車寅次郎, keyName:車さくら*)

log class of recordNew

--> (*record*)


########################

set keyRecord to "keyName3"

set valueRecord to "車竜造"


set recordAddNew to (run script "return {" & keyRecord & ":\"" & valueRecord & "\"}") as record


set recordNew to recordNew & recordAddNew as record

log recordNew

-->(*keyName1:車寅次郎, keyName2:車さくら, keyName3:車竜造*)

log class of recordNew

--> (*record*)



########################

set keyRecord to "keyName4"

set valueRecord to "車つね"


set recordAddNew to (run script "return {" & keyRecord & ":\"" & valueRecord & "\"}") as record


set recordNew to recordNew & recordAddNew as record

log recordNew

-->(*keyName1:車寅次郎, keyName2:車さくら, keyName3:車竜造, keyName4:車つね*)

log class of recordNew

--> (*record*)


log (count of recordNew)

-->(*4*)


log contents of recordNew

--> (*keyName1:車寅次郎, keyName2:車さくら, keyName3:車竜造, keyName4:車つね*)


########################


log keyName4 of recordNew

--> (*車つね*)

log keyName1 of recordNew

-->(*車寅次郎*)

|

[record]レコードの作り方色々

#!/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.4"
use framework "Foundation"
use scripting additions


set recordTMP to {} as record

set strAddItem to ("{|AAAAA|:\"BBBB\"}") as text

set recordTMP to recordTMP & (run script "return " & strAddItem & "")

set strAddItem to ("{|CCCCC|:\"DDDDD\"}") as text
set recordTMP to recordTMP & (run script "return " & strAddItem & "")

log recordTMP
-->(*AAAAA:BBBB, CCCCC:DDDDD*)
log class of recordTMP
-->(*record*)

#!/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.4"
use framework "Foundation"
use scripting additions

local localKey

set {localKey:strValue} to {localKey:"BBBB"} as record

set recordTEMP to {localKey:strValue} as record
-->(*localKey:BBBB*)

set localKey of recordTEMP to "CCCC"
-->(*localKey:CCCC*)


#!/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.4"
use framework "Foundation"
use scripting additions


set listTemp to {"AAA", "BBB"}
listTemp
--> {"AAA", "BBB"}
log class of listTemp (*list*)

set listDist to {|CCCC|:listTemp}
listDist
--> {|CCCC|:{"AAA", "BBB"}}
log class of listDist (*record*)

set end of listDist's |CCCC| to "DDDD"
listDist
--> {|CCCC|:{"AAA", "BBB","DDDD"}}
log class of listDist (*record*)

listTemp
-->{"AAA", "BBB","DDDD"}
log class of listTemp (*list*)



#!/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.4"
use framework "Foundation"
use scripting additions


set recordTMP to {} as record

set strKey to "AAAAA" as text

set strValue to "BBBB" as text


set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record


set recordTMP to recordTMP & strAddItem as record
-->{AAAAA:"BBBB"}


|

[Sort]レコードのソート(値順)

#!/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.4"
use framework "Foundation"
use scripting additions

property objMe : a reference to current application
property objNSDictionary : a reference to objMe's NSDictionary
property objNSMutableDictionary : a reference to objMe's NSMutableDictionary

set recordTMP to {} as record
########################
set strKey to "AAAA" as text

set strValue to "BBBB" as text

set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record
########################
set strKey to "CCCC" as text

set strValue to "DDDD" as text
set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record
########################
set strKey to "EEEE" as text

set strValue to "FFFF" as text
set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record

########################
set strKey to "GGGG" as text

set strValue to "HHHH" as text
set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record

########################
###出来上がったレコード
log recordTMP
-->(*AAAA:BBBB, CCCC:DDDD, EEEE:FFFF, GGGG:HHHH*)
###レコードの数
set numCntRecord to count of recordTMP
log numCntRecord
-->(*4*)
###可変レコードに
set ocidDictionary to objNSMutableDictionary's dictionaryWithDictionary:recordTMP
###キーの値をリストに
set ocidAllValues to ocidDictionary's allValues()
###キーの値が未ソートの処理前
log ocidAllValues as list
-->(*DDDD, BBBB, HHHH, FFFF*)
###ソートの方法の定義
set theDescriptor to objMe's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:true selector:"localizedStandardCompare:"
###並び替え
set ocidSortedAllValues to (ocidAllValues's sortedArrayUsingDescriptors:{theDescriptor})
log ocidSortedAllValues as list
-->(*BBBB, DDDD, FFFF, HHHH*)
###並び変わった値を順番に
repeat with ocidValues in ocidSortedAllValues
log ocidValues as text
-->(*BBBB*)
-->(*DDDD*)
-->(*FFFF*)
-->(*HHHH*)
end repeat

|

[Sort]レコードのソート(キー順)

#!/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.4"
use framework "Foundation"
use scripting additions

property objMe : a reference to current application
property objNSDictionary : a reference to objMe's NSDictionary
property objNSMutableDictionary : a reference to objMe's NSMutableDictionary

set recordTMP to {} as record
########################
set strKey to "AAAA" as text

set strValue to "BBBB" as text

set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record
########################
set strKey to "CCCC" as text

set strValue to "DDDD" as text
set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record
########################
set strKey to "EEEE" as text

set strValue to "FFFF" as text
set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record

########################
set strKey to "GGGG" as text

set strValue to "HHHH" as text
set strAddItem to (run script "return {" & strKey & ":\"" & strValue & "\"}") as record

set recordTMP to recordTMP & strAddItem as record

########################
###出来上がったレコード
log recordTMP
-->(*AAAA:BBBB, CCCC:DDDD, EEEE:FFFF, GGGG:HHHH*)
###レコードの数
set numCntRecord to count of recordTMP
log numCntRecord
-->(*4*)
###可変レコードに
set ocidDictionary to objNSMutableDictionary's dictionaryWithDictionary:recordTMP
###キーの値をリストに
set ocidAllKeys to ocidDictionary's allKeys()
###キーの値が未ソートの処理前
log ocidAllKeys as list
-->(*CCCC, AAAA, GGGG, EEEE*)
###ソートの方法の定義
set theDescriptor to objMe's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:true selector:"localizedStandardCompare:"
###並び替え
set ocidSortedAllKeys to (ocidAllKeys's sortedArrayUsingDescriptors:{theDescriptor})
log ocidSortedAllKeys as list
-->(*AAAA, CCCC, EEEE, GGGG*)
###並び変わったキー値を順番に
repeat with ocidKey in ocidSortedAllKeys
log ocidKey as text
-->(*AAAA*)
-->(*CCCC*)
-->(*EEEE*)
-->(*GGGG*)
end repeat
log "#######"
###並び変わった値を順番に
repeat with ocidKey in ocidSortedAllKeys
log (ocidDictionary's valueForKey:ocidKey) as text
-->(*BBBB*)
-->(*DDDD*)
-->(*FFFF*)
-->(*HHHH*)
end repeat

|

その他のカテゴリー

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