フォント関連のSlicesRootAttributesの追加
【スクリプトエディタで開く】 |
SlicesRootAttributes.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 | Finderの検索の選択肢にフォント関連の項目を追加します |
| 006 | クラシックな記述で書いてみた |
| 007 | ドメインは |
| 008 | com.apple.finder |
| 009 | キー |
| 010 | SlicesRootAttributes |
| 011 | 値は フォント関連のみ |
| 012 | kMDItemFonts |
| 013 | kMDItemFonts.Description |
| 014 | com_apple_ats_name_postscript |
| 015 | com_apple_ats_name_family |
| 016 | com_apple_ats_name_full |
| 017 | com_apple_ats_name_style |
| 018 | com_apple_ats_name_fond |
| 019 |
|
| 020 |
|
| 021 | com.cocolog-nifty.quicktimer.icefloe *) |
| 022 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 023 | use AppleScript version "2.8" |
| 024 | use scripting additions |
| 025 |
|
| 026 | set listAddAttributes to {"kMDItemFonts", "kMDItemFonts.Description", "com_apple_ats_name_postscript", "com_apple_ats_name_family", "com_apple_ats_name_full", "com_apple_ats_name_style", "com_apple_ats_name_fond"} as list |
| 027 |
|
| 028 | #コマンド実行 |
| 029 | set strCmd to ("/usr/bin/defaults read com.apple.finder SlicesRootAttributes") as text |
| 030 | set strStdOut to (do shell script strCmd) as text |
| 031 | #テキスト整形して |
| 032 | set strStdOut to doReplace(strStdOut, "\"", "") as text |
| 033 | set strStdOut to doReplace(strStdOut, ",", "") as text |
| 034 | set strStdOut to doReplace(strStdOut, space & space, "") as text |
| 035 | #リストに |
| 036 | set strDelim to AppleScript's text item delimiters |
| 037 | set AppleScript's text item delimiters to return |
| 038 | set listOrgArray to every text item of strStdOut |
| 039 | set AppleScript's text item delimiters to strDelim |
| 040 |
|
| 041 | repeat with itemAttributes in listAddAttributes |
| 042 | #含まれていないなら 追加 |
| 043 | if listOrgArray does not contain itemAttributes then |
| 044 | set strCmd to ("/usr/bin/defaults write com.apple.finder SlicesRootAttributes -array-add '" & itemAttributes & "'") as text |
| 045 | try |
| 046 | do shell script strCmd |
| 047 | on error strErrMsg number numErrNo |
| 048 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 049 | return false |
| 050 | end try |
| 051 | end if |
| 052 | end repeat |
| 053 |
|
| 054 | return 0 |
| 055 |
|
| 056 | ############################ |
| 057 | #文字の置換 |
| 058 | to doReplace(argOrignalText, argSearchText, argReplaceText) |
| 059 | set strDelim to AppleScript's text item delimiters |
| 060 | set AppleScript's text item delimiters to argSearchText |
| 061 | set listDelim to every text item of argOrignalText |
| 062 | set AppleScript's text item delimiters to argReplaceText |
| 063 | set strReturn to listDelim as text |
| 064 | set AppleScript's text item delimiters to strDelim |
| 065 | return strReturn |
| 066 | end doReplace |
| AppleScriptで生成しました |
|---|