AppleScript名:YAMLのじっけん4 |
— Created 2017-02-16 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "YAML" –https://github.com/mirek/YAML.framework –YAMLの文字列からオブジェクトを生成する set aYAMLstr to " – name: Smith email: smith@mail.com – name: Shelton email: shelton@mail.com – name: Kelly email: kelly@mail.com " set aRes to (retObjectFromYAMLString(aYAMLstr) of me) as list of string or string log result –> {{{name:"Smith", email:"smith@mail.com"}, {name:"Shelton", email:"shelton@mail.com"}, {name:"Kelly", email:"kelly@mail.com"}}} set bYAMLstr to " names: [Smith, Shelton, Kelly] emails: [smith@mail.com, shelton@mail.com, kelly@mail.com] " set bRes to retObjectFromYAMLString(bYAMLstr) of me log result –> {{names:{"Smith", "Shelton", "Kelly"}, emails:{"smith@mail.com", "shelton@mail.com", "kelly@mail.com"}}} –オブジェクト(list)からYAMLの文字列を生成する set bStr to retYAMLStringFromObject(bRes) log result (* "— – names: – Smith – Shelton – Kelly emails: – smith@mail.com – shelton@mail.com – kelly@mail.com … " *) on retObjectFromYAMLString(aYAMLstr as string) set aStr to current application’s NSString’s stringWithString:aYAMLstr set aData to aStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aData to current application’s YAMLSerialization’s objectsWithYAMLString:aStr options:(4096) |error|:(missing value) return aData as list of string or string end retObjectFromYAMLString on retYAMLStringFromObject(anObject) set aString to (current application’s YAMLSerialization’s createYAMLStringWithObject:anObject options:(1) |error|:(missing value)) as list of string or string return aString end retYAMLStringFromObject |
カテゴリー: Text
YAMLのじっけん
AppleScript名:YAMLのじっけん |
— Created 2017-02-16 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "YAML" –https://github.com/mirek/YAML.framework –YAMLの文字列からオブジェクトを生成する set aYAMLstr to " items: – name: Foo – name: Bar " set aStr to current application’s NSString’s stringWithString:aYAMLstr set aData to aStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aData to (current application’s YAMLSerialization’s objectsWithYAMLString:aStr options:(4096) |error|:(missing value)) as list of string or string log result –> {{items:{{name:"Foo"}, {name:"Bar"}}}} –オブジェクトからYAMLの文字列を取得する set aString to (current application’s YAMLSerialization’s createYAMLStringWithObject:aData options:(1) |error|:(missing value)) as string (* –> "— – items: – name: Foo – name: Bar …" *) |
JSONデータからのしぼりこみ
AppleScript名:JSONデータからのしぼりこみ |
— Created 2016-11-16 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions set theJSON to "{\"timeblocksDefs\": { \"normal\": { \"morning\": \"06-09\", \"day\": \"09-18\", \"primetime\": \"18-22\", \"nighttime\": \"22-06\" }, \"lateprime\": { \"morning\": \"06-09\", \"day\": \"09-19\", \"primetime\": \"19-23\", \"nighttime\": \"23-06\" } }} " set theDict to my convertJSONToDictionary:theJSON set theResult to (theDict’s valueForKeyPath:"timeblocksDefs.lateprime") — convert to AS equivalent set theResult to item 1 of ((current application’s NSArray’s arrayWithObject:theResult) as list) on convertJSONToDictionary:jsonString set aString to current application’s NSString’s stringWithString:jsonString set theData to aString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set {theDict, theError} to current application’s NSJSONSerialization’s JSONObjectWithData:theData options:0 |error|:(reference) if theDict is missing value then error (theError’s localizedDescription() as text) number -10000 return theDict end convertJSONToDictionary: |
現在のLocaleのIdentifier文字を取得する
AppleScript名:現在のLocaleのIdentifier文字を取得する.scpt |
use AppleScript version "2.7" use scripting additions use framework "Foundation" set aLoc to (current application’s NSLocale’s currentLocale()’s identifier()) as anything log aLoc –> "ja_JP" set aLoc to (current application’s NSLocale’s systemLocale()’s identifier()) as anything log aLoc –> (__NSCFLocale) <__NSCFLocale: 0x6180000f5480> set isoCountry to (current application’s NSLocale’s ISOCountryCodes()) as anything log isoCountry –> (NSArray) {"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"} set isoCurrency to (current application’s NSLocale’s ISOCurrencyCodes()) as anything log isoCurrency –> {"ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", "ANG", "AOA", "AOK", "AON", "AOR", "ARA", "ARL", "ARM", "ARP", "ARS", "ATS", "AUD", "AWG", "AZM", "AZN", "BAD", "BAM", "BAN", "BBD", "BDT", "BEC", "BEF", "BEL", "BGL", "BGM", "BGN", "BGO", "BHD", "BIF", "BMD", "BND", "BOB", "BOL", "BOP", "BOV", "BRB", "BRC", "BRE", "BRL", "BRN", "BRR", "BRZ", "BSD", "BTN", "BUK", "BWP", "BYB", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLE", "CLF", "CLP", "CNX", "CNY", "COP", "COU", "CRC", "CSD", "CSK", "CUC", "CUP", "CVE", "CYP", "CZK", "DDM", "DEM", "DJF", "DKK", "DOP", "DZD", "ECS", "ECV", "EEK", "EGP", "EQE", "ERN", "ESA", "ESB", "ESP", "ETB", "EUR", "FIM", "FJD", "FKP", "FRF", "GBP", "GEK", "GEL", "GHC", "GHS", "GIP", "GMD", "GNF", "GNS", "GQE", "GRD", "GTQ", "GWE", "GWP", "GYD", "HKD", "HNL", "HRD", "HRK", "HTG", "HUF", "IDR", "IEP", "ILP", "ILR", "ILS", "INR", "IQD", "IRR", "ISJ", "ISK", "ITL", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRH", "KRO", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LSM", "LTL", "LTT", "LUC", "LUF", "LUL", "LVL", "LVR", "LYD", "MAD", "MAF", "MCF", "MDC", "MDL", "MGA", "MGF", "MKD", "MKN", "MLF", "MMK", "MNT", "MOP", "MRO", "MTL", "MTP", "MUR", "MVP", "MVR", "MWK", "MXN", "MXP", "MXV", "MYR", "MZE", "MZM", "MZN", "NAD", "NGN", "NIC", "NIO", "NLG", "NOK", "NPR", "NZD", "OMR", "PAB", "PEI", "PEN", "PES", "PGK", "PHP", "PKR", "PLN", "PLZ", "PTE", "PYG", "QAR", "RHD", "ROL", "RON", "RSD", "RUB", "RUR", "RWF", "SAR", "SBD", "SCR", "SDD", "SDG", "SDP", "SEK", "SGD", "SHP", "SIT", "SKK", "SLL", "SOS", "SRD", "SRG", "SSP", "STD", "SUR", "SVC", "SYP", "SZL", "THB", "TJR", "TJS", "TMM", "TMT", "TND", "TOP", "TPE", "TRL", "TRY", "TTD", "TWD", "TZS", "UAH", "UAK", "UGS", "UGX", "USD", "USN", "USS", "UYI", "UYP", "UYU", "UZS", "VEB", "VEF", "VND", "VNN", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XEU", "XFO", "XFU", "XOF", "XPD", "XPF", "XPT", "XRE", "XSU", "XTS", "XUA", "XXX", "YDD", "YER", "YUD", "YUM", "YUN", "YUR", "ZAL", "ZAR", "ZMK", "ZMW", "ZRN", "ZRZ", "ZWL", "ZWR", "ZWD"} set aveLoc to (current application’s NSLocale’s availableLocaleIdentifiers()) as anything log aveLoc –> {"eu", "hr_BA", "en_CM", "rw_RW", "en_SZ", "tk_Latn", "uz_Arab", "he_IL", "ar", "en_PN", "as", "en_NF", "rwk_TZ", "zh_Hant_TW", "gsw_LI", "th_TH", "ta_IN", "es_EA", "fr_GF", "ar_001", "en_RW", "tr_TR", "de_CH", "ee_TG", "en_NG", "fr_TG", "az", "fr_SC", "es_HN", "en_AG", "ru_KZ", "gsw", "dyo", "so_ET", "zh_Hant_MO", "de_BE", "km_KH", "my_MM", "mgh_MZ", "ee_GH", "es_EC", "kw_GB", "rm_CH", "en_ME", "nyn", "mk_MK", "bs_Cyrl_BA", "ar_MR", "en_BM", "ms_Arab", "en_AI", "gl_ES", "en_PR", "ha_Latn_GH", "ne_IN", "or_IN", "khq_ML", "en_MG", "pt_TL", "en_LC", "ta_SG", "jmc_TZ", "om_ET", "lv_LV", "es_US", "en_PT", "vai_Latn_LR", "to_TO", "en_NL", "cgg_UG", "ta", "en_MH", "iu_Cans_CA", "zu_ZA", "shi_Latn_MA", "brx_IN", "ar_KM", "en_AL", "te", "chr_US", "yo_BJ", "fr_VU", "pa", "tg", "ks_Arab", "kea", "te_IN", "th", "fr_RE", "ur_IN", "yo_NG", "ti", "guz_KE", "tk", "kl_GL", "ksf_CM", "mua_CM", "lag_TZ", "fr_TN", "es_PA", "pl_PL", "to", "hi_IN", "dje_NE", "es_GQ", "kok_IN", "pl", "tr", "bem", "ha", "ckb", "lg", "fr_GN", "en_PW", "en_NO", "nyn_UG", "sr_Latn_RS", "pa_Guru", "he", "swc_CD", "ug_Arab", "lu_CD", "mgo_CM", "sn_ZW", "en_BS", "ps_AF", "da", "ms_Latn_SG", "ps", "ln", "pt", "iu_Cans", "hi", "lo", "ebu", "de", "gu_IN", "seh", "en_CX", "en_ZM", "tzm_Latn_MA", "fr_HT", "fr_GP", "lt", "lu", "ln_CD", "vai_Latn", "el_GR", "lv", "en_KE", "sbp", "hr", "en_CY", "es_GT", "twq_NE", "zh_Hant_HK", "kln_KE", "fr_GQ", "chr", "hu", "es_UY", "fr_CA", "en_NR", "mer", "shi", "es_PE", "fr_SN", "bez", "sw_TZ", "kkj", "hy", "kk_Cyrl_KZ", "en_CZ", "teo_KE", "teo", "dz_BT", "ar_JO", "mer_KE", "khq", "ln_CF", "nn_NO", "en_MO", "ar_TD", "dz", "ses", "en_BW", "en_AS", "ar_IL", "ms_Latn_BN", "bo_CN", "nnh", "teo_UG", "hy_AM", "ln_CG", "sr_Latn_BA", "en_MP", "ksb_TZ", "ar_SA", "ar_LY", "en_AT", "so_KE", "fr_CD", "af_NA", "en_NU", "es_PH", "en_KI", "en_JE", "lkt", "en_AU", "fa_IR", "uz_Latn_UZ", "ky_Cyrl", "zh_Hans_CN", "ewo_CM", "fr_PF", "ca_IT", "en_BZ", "ar_KW", "pt_GW", "fr_FR", "am_ET", "en_VC", "fr_DJ", "fr_CF", "es_SV", "en_MS", "pt_ST", "ar_SD", "luy_KE", "swc", "de_LI", "fr_CG", "zh_Hans_SG", "en_MT", "ewo", "af_ZA", "om_KE", "nl_SR", "es_ES", "es_DO", "ar_IQ", "fr_CH", "nnh_CM", "es_419", "en_MU", "en_US_POSIX", "yav_CM", "luo_KE", "dua_CM", "et_EE", "en_IE", "ak_GH", "rwk", "es_CL", "kea_CV", "fr_CI", "fr_BE", "en_NZ", "ky_Cyrl_KG", "en_LR", "en_KN", "nb_SJ", "sg", "sr_Cyrl_RS", "ru_RU", "en_ZW", "sv_AX", "si", "ga_IE", "en_VG", "sk", "agq_CM", "fr_BF", "naq_NA", "sl", "en_MW", "mr_IN", "az_Latn", "en_LS", "de_AT", "ka", "sn", "sr_Latn_ME", "fr_NC", "so", "is_IS", "twq", "ig_NG", "sq", "fo_FO", "sr", "tzm", "ga", "om", "en_LT", "bas_CM", "ki", "nl_BE", "ar_QA", "sv", "kk", "sw", "es_CO", "az_Latn_AZ", "rn_BI", "or", "kl", "ca", "en_VI", "km", "kn", "en_LU", "fr_SY", "ar_TN", "en_JM", "fr_PM", "ko", "fr_NE", "fr_MA", "gl", "ru_MD", "saq_KE", "ks", "fr_CM", "gv_IM", "fr_BI", "en_LV", "ks_Arab_IN", "es_NI", "en_GB", "kw", "nl_SX", "dav_KE", "tr_CY", "ky", "en_UG", "tzm_Latn", "en_TC", "nus_SD", "ar_EG", "fr_BJ", "gu", "es_PR", "fr_RW", "sr_Cyrl_BA", "gv", "fr_MC", "cs", "bez_TZ", "es_CR", "asa_TZ", "ar_EH", "ms_Arab_BN", "mn_Cyrl", "sbp_TZ", "ha_Latn_NE", "lt_LT", "mfe", "en_GD", "cy", "ca_FR", "es_BO", "fr_BL", "bn_IN", "uz_Cyrl_UZ", "az_Cyrl", "en_IM", "sw_KE", "en_SB", "ur_PK", "pa_Arab", "haw_US", "ar_SO", "en_IN", "ha_Latn", "fil", "fr_MF", "en_WS", "es_CU", "ja_JP", "en_SC", "en_IO", "pt_PT", "en_HK", "en_GG", "fr_MG", "de_LU", "ms_Latn_MY", "tg_Cyrl", "en_SD", "shi_Tfng", "ln_AO", "ug_Arab_CN", "as_IN", "en_GH", "ro_RO", "jgo_CM", "dua", "en_UM", "en_SE", "kn_IN", "en_KY", "vun_TZ", "kln", "en_GI", "ca_ES", "rof", "pt_CV", "kok", "pt_BR", "ar_DJ", "zh", "fi_FI", "tg_Cyrl_TJ", "es_PY", "ar_SS", "mua", "sr_Cyrl_ME", "vai_Vaii_LR", "en_001", "xog_UG", "en_TK", "si_LK", "en_SG", "nl_NL", "vi", "sv_SE", "pt_AO", "fr_DZ", "ca_AD", "xog", "en_IS", "nb", "seh_MZ", "es_AR", "sk_SK", "en_SH", "ti_ER", "nd", "az_Cyrl_AZ", "zu", "ne", "nd_ZW", "el_CY", "en_IT", "nl_BQ", "da_GL", "ja", "rm", "fr_ML", "rn", "en_VU", "rof_TZ", "ro", "ebu_KE", "ru_KG", "en_SI", "sg_CF", "mfe_MU", "nl", "brx", "bs_Latn", "fa", "zgh_MA", "en_GM", "shi_Latn", "en_FI", "nn", "en_EE", "ru", "kam_KE", "vai_Vaii", "ar_ER", "ti_ET", "rw", "ff", "luo", "fa_AF", "ha_Latn_NG", "nl_CW", "en_HR", "en_FJ", "fi", "pt_MO", "be", "en_US", "en_TO", "en_SK", "bg", "ru_BY", "it_IT", "ml_IN", "gsw_CH", "fo", "sv_FI", "en_FK", "nus", "ta_LK", "vun", "sr_Latn", "fr", "en_SL", "bm", "ar_BH", "guz", "bn", "bo", "ar_SY", "lo_LA", "ne_NP", "uz_Latn", "be_BY", "es_IC", "sr_Latn_XK", "ar_MA", "pa_Guru_IN", "br", "luy", "kde_TZ", "bs", "hu_HU", "ar_AE", "en_HU", "zh_Hans", "en_FM", "sq_AL", "ko_KP", "en_150", "en_DE", "fr_MQ", "en_CA", "en_TR", "ro_MD", "es_VE", "fr_WF", "mt_MT", "kab", "nmg_CM", "ru_UA", "fr_MR", "tk_Latn_TM", "zh_Hans_MO", "mn_Cyrl_MN", "bs_Cyrl", "sw_UG", "ko_KR", "en_DG", "bo_IN", "en_CC", "shi_Tfng_MA", "lag", "it_SM", "en_TT", "ms_Arab_MY", "sq_MK", "ms_Latn", "bem_ZM", "kde", "ar_OM", "cgg", "bas", "kam", "zh_Hant", "es_MX", "en_GU", "fr_MU", "fr_KM", "ar_LB", "en_BA", "en_TV", "sr_Cyrl", "dje", "kab_DZ", "fil_PH", "vai", "hr_HR", "bs_Latn_BA", "nl_AW", "dav", "so_SO", "ar_PS", "en_FR", "uz_Cyrl", "ff_SN", "en_BB", "ki_KE", "naq", "en_SS", "mg_MG", "mas_KE", "en_RO", "en_PG", "mgh", "dyo_SN", "mas", "agq", "bn_BD", "haw", "nb_NO", "da_DK", "en_DK", "saq", "ug", "cy_GB", "fr_YT", "jmc", "ses_ML", "en_PH", "de_DE", "ar_YE", "bm_ML", "yo", "lkt_US", "uz_Arab_AF", "jgo", "uk", "sl_SI", "en_CH", "asa", "lg_UG", "mgo", "id_ID", "en_NA", "en_GY", "zgh", "pt_MZ", "fr_LU", "kk_Cyrl", "mas_TZ", "ur", "en_DM", "ta_MY", "en_BE", "mg", "fr_GA", "ka_GE", "nmg", "en_TZ", "eu_ES", "ar_DZ", "id", "so_DJ", "yav", "mk", "pa_Arab_PK", "ml", "en_ER", "ig", "mn", "ksb", "uz", "vi_VN", "ii", "en_PK", "ee", "mr", "ms", "en_ES", "sq_XK", "it_CH", "mt", "en_CK", "br_FR", "sr_Cyrl_XK", "ksf", "en_SX", "bg_BG", "en_PL", "af", "el", "cs_CZ", "fr_TD", "zh_Hans_HK", "is", "my", "en", "it", "ii_CN", "eo", "iu", "en_ZA", "en_AD", "ak", "en_RU", "kkj_CM", "am", "es", "et", "uk_UA"} set isoLang to (current application’s NSLocale’s ISOLanguageCodes()) as anything log isoLang –> {"aa", "ab", "ace", "ach", "ada", "ady", "ae", "af", "afa", "afh", "agq", "ain", "ak", "akk", "ale", "alg", "alt", "am", "an", "ang", "anp", "apa", "ar", "arc", "arn", "arp", "art", "arw", "as", "asa", "ast", "ath", "aus", "av", "awa", "ay", "az", "ba", "bad", "bai", "bal", "ban", "bas", "bat", "bax", "bbj", "be", "bej", "bem", "ber", "bez", "bfd", "bg", "bh", "bho", "bi", "bik", "bin", "bkm", "bla", "bm", "bn", "bnt", "bo", "br", "bra", "brx", "bs", "bss", "btk", "bua", "bug", "bum", "byn", "byv", "ca", "cad", "cai", "car", "cau", "cay", "cch", "ce", "ceb", "cel", "cgg", "ch", "chb", "chg", "chk", "chm", "chn", "cho", "chp", "chr", "chy", "ckb", "cmc", "co", "cop", "cpe", "cpf", "cpp", "cr", "crh", "crp", "cs", "csb", "cu", "cus", "cv", "cy", "da", "dak", "dar", "dav", "day", "de", "del", "den", "dgr", "din", "dje", "doi", "dra", "dsb", "dua", "dum", "dv", "dyo", "dyu", "dz", "dzg", "ebu", "ee", "efi", "egy", "eka", "el", "elx", "en", "enm", "eo", "es", "et", "eu", "ewo", "fa", "fan", "fat", "ff", "fi", "fil", "fiu", "fj", "fo", "fon", "fr", "frm", "fro", "frr", "frs", "fur", "fy", "ga", "gaa", "gay", "gba", "gd", "gem", "gez", "gil", "gl", "gmh", "gn", "goh", "gon", "gor", "got", "grb", "grc", "gsw", "gu", "guz", "gv", "gwi", "ha", "hai", "haw", "he", "hi", "hil", "him", "hit", "hmn", "ho", "hr", "hsb", "ht", "hu", "hup", "hy", "hz", "ia", "iba", "ibb", "id", "ie", "ig", "ii", "ijo", "ik", "ilo", "inc", "ine", "inh", "io", "ira", "iro", "is", "it", "iu", "ja", "jbo", "jgo", "jmc", "jpr", "jrb", "jv", "ka", "kaa", "kab", "kac", "kaj", "kam", "kar", "kaw", "kbd", "kbl", "kcg", "kde", "kea", "kfo", "kg", "kha", "khi", "kho", "khq", "ki", "kj", "kk", "kkj", "kl", "kln", "km", "kmb", "kn", "ko", "kok", "kos", "kpe", "kr", "krc", "krl", "kro", "kru", "ks", "ksb", "ksf", "ksh", "ku", "kum", "kut", "kv", "kw", "ky", "la", "lad", "lag", "lah", "lam", "lb", "lez", "lg", "li", "lkt", "ln", "lo", "lol", "loz", "lt", "lu", "lua", "lui", "lun", "luo", "lus", "luy", "lv", "mad", "maf", "mag", "mai", "mak", "man", "map", "mas", "mde", "mdf", "mdr", "men", "mer", "mfe", "mg", "mga", "mgh", "mgo", "mh", "mi", "mic", "min", "mis", "mk", "mkh", "ml", "mn", "mnc", "mni", "mno", "mo", "moh", "mos", "mr", "ms", "mt", "mua", "mul", "mun", "mus", "mwl", "mwr", "my", "mye", "myn", "myv", "na", "nah", "nai", "nap", "naq", "nb", "nd", "nds", "ne", "new", "ng", "nia", "nic", "niu", "nl", "nmg", "nn", "nnh", "no", "nog", "non", "nqo", "nr", "nso", "nub", "nus", "nv", "nwc", "ny", "nym", "nyn", "nyo", "nzi", "oc", "oj", "om", "or", "os", "osa", "ota", "oto", "pa", "paa", "pag", "pal", "pam", "pap", "pau", "peo", "phi", "phn", "pi", "pl", "pon", "pra", "pro", "ps", "pt", "qu", "raj", "rap", "rar", "rm", "rn", "ro", "roa", "rof", "rom", "ru", "rup", "rw", "rwk", "sa", "sad", "sah", "sai", "sal", "sam", "saq", "sas", "sat", "sba", "sbp", "sc", "scn", "sco", "sd", "se", "see", "seh", "sel", "sem", "ses", "sg", "sga", "sgn", "shi", "shn", "shu", "si", "sid", "sio", "sit", "sk", "sl", "sla", "sm", "sma", "smi", "smj", "smn", "sms", "sn", "snk", "so", "sog", "son", "sq", "sr", "srn", "srr", "ss", "ssa", "ssy", "st", "su", "suk", "sus", "sux", "sv", "sw", "swb", "swc", "syc", "syr", "ta", "tai", "te", "tem", "teo", "ter", "tet", "tg", "th", "ti", "tig", "tiv", "tk", "tkl", "tl", "tlh", "tli", "tmh", "tn", "to", "tog", "tpi", "tr", "trv", "ts", "tsi", "tt", "tum", "tup", "tut", "tvl", "tw", "twq", "ty", "tyv", "tzm", "udm", "ug", "uga", "uk", "umb", "und", "ur", "uz", "vai", "ve", "vi", "vo", "vot", "vun", "wa", "wae", "wak", "wal", "war", "was", "wen", "wo", "xal", "xh", "xog", "yao", "yap", "yav", "ybb", "yi", "yo", "ypk", "yue", "za", "zap", "zbl", "zen", "zgh", "zh", "znd", "zu", "zun", "zxx", "zza"} set commonCurrency to (current application’s NSLocale’s commonISOCurrencyCodes()) as anything log commonCurrency –> (NSArray) {"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GWP", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZE", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SKK", "SLL", "SOS", "SRD", "SSP", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "ZAR", "ZMW"} set aLoc to (current application’s NSLocale’s localeIdentifierFromWindowsLocaleCode:1041) as anything log aLoc –> "ja_JP" — https://msdn.microsoft.com/ja-jp/library/Cc392381.aspx set aLocID to (current application’s NSLocale’s windowsLocaleCodeFromLocaleIdentifier:"ja_JP") as anything log aLocID –> 1041 set prefLang to (current application’s NSLocale’s preferredLanguages()) as anything log prefLang –> {"ja", "en-US", "en-GB", "fr", "en"} set aLangDIrect1 to (current application’s NSLocale’s characterDirectionForLanguage:"ja") as anything –日本語 log aLangDIrect1 –> 1 –NSLocaleLanguageDirectionLeftToRight set aLangDIrect2 to (current application’s NSLocale’s characterDirectionForLanguage:"ar") as anything –アラビア語 log aLangDIrect2 –> 2 –NSLocaleLanguageDirectionRightToLeft set aLangLineDIrect1 to (current application’s NSLocale’s lineDirectionForLanguage:"ja") as anything –日本語 log aLangLineDIrect1 –> 3 –NSLocaleLanguageDirectionTopToBottom set aLangLineDIrect2 to (current application’s NSLocale’s lineDirectionForLanguage:"ar") as anything –アラビア語 log aLangLineDIrect2 –> 3 –NSLocaleLanguageDirectionTopToBottom |
すべてのLocaleから各種情報を取得
AppleScript名:すべてのLocaleから各種情報を取得 |
— Created 2015-10-03 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set allLocaleIdentifiers to (current application’s NSLocale’s availableLocaleIdentifiers()) as list set cList to {} repeat with i in allLocaleIdentifiers set j to contents of i set tmpLoc to (current application’s NSLocale’s alloc()’s initWithLocaleIdentifier:j) set aLangCode to (tmpLoc’s objectForKey:(current application’s NSLocaleLanguageCode)) as text set aCountryCode to (tmpLoc’s objectForKey:(current application’s NSLocaleCountryCode)) as text set aCCYSymbol to (tmpLoc’s objectForKey:(current application’s NSLocaleCurrencySymbol)) as text set aLocID to (tmpLoc’s objectForKey:(current application’s NSLocaleIdentifier)) as text –set aCountryName to (tmpLoc’s displayNameForKey:(current application’s NSLocaleCountryCode)) set locIDDisplayName to (tmpLoc’s displayNameForKey:(current application’s NSLocaleIdentifier) value:aLocID) as text set the end of cList to {aLocID, aLangCode, aCountryCode, aCCYSymbol, locIDDisplayName} end repeat cList –> {{"eu", "eu", "missing value", "¤", "euskara"},…. {"ja_JP", "ja", "JP", "¥", "日本語 (日本)"}, ….. {"ja", "ja", "missing value", "¤", "日本語"}, ………., {"en_US", "en", "US", "$", "English (United States)"}, {"en_US_POSIX", "en", "US", "$", "English (United States, Computer)"}, {"zh-Hans", "zh", "missing value", "¤", "中文(简体)"},….. {"zh-Hant", "zh", "missing value", "¤", "中文(繁體)"}, ….{"zh-Hans_HK", "zh", "HK", "HK$", "中文(简体、中国香港特别行政区)"},} |
Current Localeから各種情報を取得する
AppleScript名:Current Localeから各種情報を取得する |
— Created 2016-10-12 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set curLocale to current application’s NSLocale’s currentLocale() set aDS1 to curLocale’s objectForKey:(current application’s NSLocaleDecimalSeparator) –> (NSString) "." set aDS2 to curLocale’s objectForKey:(current application’s NSLocaleGroupingSeparator) –> (NSString) "," set aDS3 to curLocale’s objectForKey:(current application’s NSLocaleCurrencySymbol) –> (NSString) "¥" set aDS4 to curLocale’s objectForKey:(current application’s NSLocaleCurrencyCode) –> (NSString) "JPY" set aDS5 to curLocale’s objectForKey:(current application’s NSLocaleCollatorIdentifier) –> (NSString) "ja-JP" set aDS6 to curLocale’s objectForKey:(current application’s NSLocaleQuotationBeginDelimiterKey) –> (NSString) "「" set aDS7 to curLocale’s objectForKey:(current application’s NSLocaleQuotationEndDelimiterKey) –> (NSString) "」" set aDS8 to curLocale’s objectForKey:(current application’s NSLocaleAlternateQuotationBeginDelimiterKey) –> (NSString) "『" set aDS9 to curLocale’s objectForKey:(current application’s NSLocaleAlternateQuotationEndDelimiterKey) –> (NSString) "』" set aDS10 to curLocale’s objectForKey:(current application’s NSLocaleIdentifier) –> (NSString) "ja_JP" set aDS11 to curLocale’s objectForKey:(current application’s NSLocaleLanguageCode) –> (NSString) "ja" set aDS12 to curLocale’s objectForKey:(current application’s NSLocaleCountryCode) –> (NSString) "JP" set aDS13 to curLocale’s objectForKey:(current application’s NSLocaleScriptCode) –> missing value set aDS14 to curLocale’s objectForKey:(current application’s NSLocaleVariantCode) –> missing value set aDS15 to curLocale’s objectForKey:(current application’s NSLocaleExemplarCharacterSet) –> (__NSCFCharacterSet) <__NSCFCharacterSet: 0x60800124d890> set aDS16 to curLocale’s objectForKey:(current application’s NSLocaleCalendar) –> (_NSCopyOnWriteCalendarWrapper) <_NSCopyOnWriteCalendarWrapper: 0x610000232ca0> set aDS17 to curLocale’s objectForKey:(current application’s NSLocaleCollationIdentifier) –> missing value set aDS18 to curLocale’s objectForKey:(current application’s NSLocaleUsesMetricSystem) –> (NSNumber) 1 set aDS19 to curLocale’s objectForKey:(current application’s NSLocaleMeasurementSystem) –> (NSString) "Metric" |
Locale情報を取得する
AppleScript名:Locale情報を取得する |
— Created 2015-09-11 by Takaaki Naganoya — 2015 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aLocale to (current application’s NSLocale’s currentLocale’s objectForKey:(current application’s NSLocaleIdentifier)) as list of string or string –as anything –> "ja_JP" set aLangList to (current application’s NSLocale’s preferredLanguages()) as list of string or string –as anything –> {"ja", "en-US", "en-GB", "fr", "en"} set aLocList to (current application’s NSLocale’s availableLocaleIdentifiers()) as list of string or string –as anything –> {"eu", "hr_BA", "en_CM", "rw_RW", "en_SZ", "tk_Latn", "uz_Arab", "he_IL", "ar", "en_PN", "as", "en_NF", "rwk_TZ", "zh_Hant_TW", "gsw_LI", "th_TH", "ta_IN", "es_EA", "fr_GF", "ar_001", "en_RW", "tr_TR", "de_CH", "ee_TG", "en_NG", "fr_TG", "az", "fr_SC", "es_HN", "en_AG", "ru_KZ", "gsw", "dyo", "so_ET", "zh_Hant_MO", "de_BE", "km_KH", "my_MM", "mgh_MZ", "ee_GH", "es_EC", "kw_GB", "rm_CH", "en_ME", "nyn", "mk_MK", "bs_Cyrl_BA", "ar_MR", "en_BM", "ms_Arab", "en_AI", "gl_ES", "en_PR", "ha_Latn_GH", "ne_IN", "or_IN", "khq_ML", "en_MG", "pt_TL", "en_LC", "ta_SG", "jmc_TZ", "om_ET", "lv_LV", "es_US", "en_PT", "vai_Latn_LR", "to_TO", "en_NL", "cgg_UG", "ta", "en_MH", "iu_Cans_CA", "zu_ZA", "shi_Latn_MA", "brx_IN", "ar_KM", "en_AL", "te", "chr_US", "yo_BJ", "fr_VU", "pa", "tg", "ks_Arab", "kea", "te_IN", "th", "fr_RE", "ur_IN", "yo_NG", "ti", "guz_KE", "tk", "kl_GL", "ksf_CM", "mua_CM", "lag_TZ", "fr_TN", "es_PA", "pl_PL", "to", "hi_IN", "dje_NE", "es_GQ", "kok_IN", "pl", "tr", "bem", "ha", "ckb", "lg", "fr_GN", "en_PW", "en_NO", "nyn_UG", "sr_Latn_RS", "pa_Guru", "he", "swc_CD", "ug_Arab", "lu_CD", "mgo_CM", "sn_ZW", "en_BS", "ps_AF", "da", "ms_Latn_SG", "ps", "ln", "pt", "iu_Cans", "hi", "lo", "ebu", "de", "gu_IN", "seh", "en_CX", "en_ZM", "tzm_Latn_MA", "fr_HT", "fr_GP", "lt", "lu", "ln_CD", "vai_Latn", "el_GR", "lv", "en_KE", "sbp", "hr", "en_CY", "es_GT", "twq_NE", "zh_Hant_HK", "kln_KE", "fr_GQ", "chr", "hu", "es_UY", "fr_CA", "en_NR", "mer", "shi", "es_PE", "fr_SN", "bez", "sw_TZ", "kkj", "hy", "kk_Cyrl_KZ", "en_CZ", "teo_KE", "teo", "dz_BT", "ar_JO", "mer_KE", "khq", "ln_CF", "nn_NO", "en_MO", "ar_TD", "dz", "ses", "en_BW", "en_AS", "ar_IL", "ms_Latn_BN", "bo_CN", "nnh", "teo_UG", "hy_AM", "ln_CG", "sr_Latn_BA", "en_MP", "ksb_TZ", "ar_SA", "ar_LY", "en_AT", "so_KE", "fr_CD", "af_NA", "en_NU", "es_PH", "en_KI", "en_JE", "lkt", "en_AU", "fa_IR", "uz_Latn_UZ", "ky_Cyrl", "zh_Hans_CN", "ewo_CM", "fr_PF", "ca_IT", "en_BZ", "ar_KW", "pt_GW", "fr_FR", "am_ET", "en_VC", "fr_DJ", "fr_CF", "es_SV", "en_MS", "pt_ST", "ar_SD", "luy_KE", "swc", "de_LI", "fr_CG", "zh_Hans_SG", "en_MT", "ewo", "af_ZA", "om_KE", "nl_SR", "es_ES", "es_DO", "ar_IQ", "fr_CH", "nnh_CM", "es_419", "en_MU", "en_US_POSIX", "yav_CM", "luo_KE", "dua_CM", "et_EE", "en_IE", "ak_GH", "rwk", "es_CL", "kea_CV", "fr_CI", "fr_BE", "en_NZ", "ky_Cyrl_KG", "en_LR", "en_KN", "nb_SJ", "sg", "sr_Cyrl_RS", "ru_RU", "en_ZW", "sv_AX", "si", "ga_IE", "en_VG", "sk", "agq_CM", "fr_BF", "naq_NA", "sl", "en_MW", "mr_IN", "az_Latn", "en_LS", "de_AT", "ka", "sn", "sr_Latn_ME", "fr_NC", "so", "is_IS", "twq", "ig_NG", "sq", "fo_FO", "sr", "tzm", "ga", "om", "en_LT", "bas_CM", "ki", "nl_BE", "ar_QA", "sv", "kk", "sw", "es_CO", "az_Latn_AZ", "rn_BI", "or", "kl", "ca", "en_VI", "km", "kn", "en_LU", "fr_SY", "ar_TN", "en_JM", "fr_PM", "ko", "fr_NE", "fr_MA", "gl", "ru_MD", "saq_KE", "ks", "fr_CM", "gv_IM", "fr_BI", "en_LV", "ks_Arab_IN", "es_NI", "en_GB", "kw", "nl_SX", "dav_KE", "tr_CY", "ky", "en_UG", "tzm_Latn", "en_TC", "nus_SD", "ar_EG", "fr_BJ", "gu", "es_PR", "fr_RW", "sr_Cyrl_BA", "gv", "fr_MC", "cs", "bez_TZ", "es_CR", "asa_TZ", "ar_EH", "ms_Arab_BN", "mn_Cyrl", "sbp_TZ", "ha_Latn_NE", "lt_LT", "mfe", "en_GD", "cy", "ca_FR", "es_BO", "fr_BL", "bn_IN", "uz_Cyrl_UZ", "az_Cyrl", "en_IM", "sw_KE", "en_SB", "ur_PK", "pa_Arab", "haw_US", "ar_SO", "en_IN", "ha_Latn", "fil", "fr_MF", "en_WS", "es_CU", "ja_JP", "en_SC", "en_IO", "pt_PT", "en_HK", "en_GG", "fr_MG", "de_LU", "ms_Latn_MY", "tg_Cyrl", "en_SD", "shi_Tfng", "ln_AO", "ug_Arab_CN", "as_IN", "en_GH", "ro_RO", "jgo_CM", "dua", "en_UM", "en_SE", "kn_IN", "en_KY", "vun_TZ", "kln", "en_GI", "ca_ES", "rof", "pt_CV", "kok", "pt_BR", "ar_DJ", "zh", "fi_FI", "tg_Cyrl_TJ", "es_PY", "ar_SS", "mua", "sr_Cyrl_ME", "vai_Vaii_LR", "en_001", "xog_UG", "en_TK", "si_LK", "en_SG", "nl_NL", "vi", "sv_SE", "pt_AO", "fr_DZ", "ca_AD", "xog", "en_IS", "nb", "seh_MZ", "es_AR", "sk_SK", "en_SH", "ti_ER", "nd", "az_Cyrl_AZ", "zu", "ne", "nd_ZW", "el_CY", "en_IT", "nl_BQ", "da_GL", "ja", "rm", "fr_ML", "rn", "en_VU", "rof_TZ", "ro", "ebu_KE", "ru_KG", "en_SI", "sg_CF", "mfe_MU", "nl", "brx", "bs_Latn", "fa", "zgh_MA", "en_GM", "shi_Latn", "en_FI", "nn", "en_EE", "ru", "kam_KE", "vai_Vaii", "ar_ER", "ti_ET", "rw", "ff", "luo", "fa_AF", "ha_Latn_NG", "nl_CW", "en_HR", "en_FJ", "fi", "pt_MO", "be", "en_US", "en_TO", "en_SK", "bg", "ru_BY", "it_IT", "ml_IN", "gsw_CH", "fo", "sv_FI", "en_FK", "nus", "ta_LK", "vun", "sr_Latn", "fr", "en_SL", "bm", "ar_BH", "guz", "bn", "bo", "ar_SY", "lo_LA", "ne_NP", "uz_Latn", "be_BY", "es_IC", "sr_Latn_XK", "ar_MA", "pa_Guru_IN", "br", "luy", "kde_TZ", "bs", "hu_HU", "ar_AE", "en_HU", "zh_Hans", "en_FM", "sq_AL", "ko_KP", "en_150", "en_DE", "fr_MQ", "en_CA", "en_TR", "ro_MD", "es_VE", "fr_WF", "mt_MT", "kab", "nmg_CM", "ru_UA", "fr_MR", "tk_Latn_TM", "zh_Hans_MO", "mn_Cyrl_MN", "bs_Cyrl", "sw_UG", "ko_KR", "en_DG", "bo_IN", "en_CC", "shi_Tfng_MA", "lag", "it_SM", "en_TT", "ms_Arab_MY", "sq_MK", "ms_Latn", "bem_ZM", "kde", "ar_OM", "cgg", "bas", "kam", "zh_Hant", "es_MX", "en_GU", "fr_MU", "fr_KM", "ar_LB", "en_BA", "en_TV", "sr_Cyrl", "dje", "kab_DZ", "fil_PH", "vai", "hr_HR", "bs_Latn_BA", "nl_AW", "dav", "so_SO", "ar_PS", "en_FR", "uz_Cyrl", "ff_SN", "en_BB", "ki_KE", "naq", "en_SS", "mg_MG", "mas_KE", "en_RO", "en_PG", "mgh", "dyo_SN", "mas", "agq", "bn_BD", "haw", "nb_NO", "da_DK", "en_DK", "saq", "ug", "cy_GB", "fr_YT", "jmc", "ses_ML", "en_PH", "de_DE", "ar_YE", "bm_ML", "yo", "lkt_US", "uz_Arab_AF", "jgo", "uk", "sl_SI", "en_CH", "asa", "lg_UG", "mgo", "id_ID", "en_NA", "en_GY", "zgh", "pt_MZ", "fr_LU", "kk_Cyrl", "mas_TZ", "ur", "en_DM", "ta_MY", "en_BE", "mg", "fr_GA", "ka_GE", "nmg", "en_TZ", "eu_ES", "ar_DZ", "id", "so_DJ", "yav", "mk", "pa_Arab_PK", "ml", "en_ER", "ig", "mn", "ksb", "uz", "vi_VN", "ii", "en_PK", "ee", "mr", "ms", "en_ES", "sq_XK", "it_CH", "mt", "en_CK", "br_FR", "sr_Cyrl_XK", "ksf", "en_SX", "bg_BG", "en_PL", "af", "el", "cs_CZ", "fr_TD", "zh_Hans_HK", "is", "my", "en", "it", "ii_CN", "eo", "iu", "en_ZA", "en_AD", "ak", "en_RU", "kkj_CM", "am", "es", "et", "uk_UA"} |
指定言語環境(Locale)の月名、曜日名を取得する
AppleScript名:指定言語環境(Locale)の月名、曜日名を取得する |
use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to getLocalizedDaynames("en_US") –> {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} set aList to getLocalizedDaynames("fr_FR") –> {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"} set aList to getLocalizedDaynames("ja_JP") –> {"日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"} set aList to getLocalizedDaynames("zh-Hans") –> {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"} set bList to getLocalizedMonthnames("en_US") –> {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"} set bList to getLocalizedMonthnames("fr_FR") –> {"janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"} set bList to getLocalizedMonthnames("ja_JP") –> {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"} set bList to getLocalizedMonthnames("zh-Hans") –> {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"} –ローカライズされた曜日名称を返す on getLocalizedDaynames(aLoc) set df to current application’s NSDateFormatter’s alloc()’s init() df’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:aLoc) set dayNames to df’s standaloneWeekdaySymbols() as list return dayNames end getLocalizedDaynames –ローカライズされた月名称を返す on getLocalizedMonthnames(aLoc) set df to current application’s NSDateFormatter’s alloc()’s init() df’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:aLoc) set monthNames to df’s standaloneMonthSymbols() as list return monthNames end getLocalizedMonthnames |
数値文字列に対して、少数点以下の数値の切り上げ、切り下げ v2
AppleScript名:数値文字列に対して、少数点以下の数値の切り上げ、切り下げ v2 |
— Created 2017-08-12 by Takaaki Naganoya — Modified 2017-08-28 by Shane Stanley use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSString : a reference to current application’s NSString property NSNumber : a reference to current application’s NSNumber property NSNumberFormatter : a reference to current application’s NSNumberFormatter property NSNumberFormatterRoundUp : a reference to current application’s NSNumberFormatterRoundUp property NSNumberFormatterRoundDown : a reference to current application’s NSNumberFormatterRoundDown set a to "0.9096617698669434" set a1Res to roundingDownNumStr(a, 2) of me set b to "0.0001830748806241899" set b1Res to roundingDownNumStr(b, 2) of me return {a1Res, b1Res} –> {0.9, 0.0} on roundingDownNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundDown) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingDownNumStr on roundingUpNumStr(aNum as string, aDigit as integer) set a to NSString’s stringWithString:aNum set aa to a’s doubleValue() set aFormatter to NSNumberFormatter’s alloc()’s init() aFormatter’s setMaximumFractionDigits:aDigit aFormatter’s setRoundingMode:(NSNumberFormatterRoundUp) set aStr to aFormatter’s stringFromNumber:aa return (aStr as text) as real end roundingUpNumStr |
数値書式関連
AppleScript名:数値書式関連 |
use AppleScript version "2.4" use framework "Foundation" use scripting additions set theNumber to 1.234567890123E+12 set theResult to formatNumber_(theNumber) –> "1,234,567,890,123" set aRes to textFromNumber_forLocale_(1.2345678E+4, "fr") –> "douze-mille-trois-cent-quarante-cinq virgule six sept huit" set aRes to textFromNumber_forLocale_(1.2345678E+4, "ja") –> "一万二千三百四十五・六七八" set aRes to formatNumber_usingFormat_(1.2345678E+4, "#,###.00;0.00;(#,##0.00)") –> "12,345.68" on formatNumber:theNumber set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setNumberStyle:(current application’s NSNumberFormatterDecimalStyle) set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end formatNumber: on textFromNumber:theNumber forLocale:localeString set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setNumberStyle:(current application’s NSNumberFormatterSpellOutStyle) set theLocale to current application’s NSLocale’s localeWithLocaleIdentifier:localeString theFormatter’s setLocale:theLocale set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end textFromNumber:forLocale: on formatNumber:theNumber usingFormat:formatString set theFormatter to current application’s NSNumberFormatter’s new() theFormatter’s setFormat:formatString theFormatter’s setLocalizesFormat:false set theResult to theFormatter’s stringFromNumber:theNumber return theResult as text end formatNumber:usingFormat: |
大きな数値同士を足し算する
巨大な数値同士を加算するAppleScriptです。
AppleScriptの数値型データが±99999999程度で指数表示になってしまうため、巨大な数値を扱うのには向いていないのですが、直接数値で扱わずに文字列として保持すれば問題はありません。
数値文字同士の計算についても、bcコマンドを使うことで四則演算+α程度は行えるので、あまり問題はないでしょう。bcコマンドを呼び出すオーバーヘッドはそれなりにあるので、すべての数値を文字列で保持したりするのは得策ではありません。必要な箇所だけ使う、といったところです。
AppleScript名:大きな数値同士を足し算する |
set a to "100000000000000000" set b to "200000000000000000" set c to addLargeNumber(a, b) of me on addLargeNumber(aNum, bNum) set aNumStr to aNum as string set bNumStr to bNum as string set aCMD to "echo \" scale=10; " & aNumStr & "+" & bNumStr & " \" | bc" set aRes to do shell script aCMD return aRes end addLargeNumber |
指定のコード体系の全パターンのコードを生成 v5
AppleScript名:指定のコード体系の全パターンのコードを生成 v5 |
–v5 外部からプロパティで与えられたルールから、初期値となる「最小値」を自前で計算するように変更 –v4 桁ごとにサブルーチンを設けるのではなく、再帰処理で1つのルーチンを多重呼び出しするように変更 –v3 コードのルールを外部供給する構成にした(処理ロジックとルールの分離が完了) –v2 各桁の最大値と最小値をプロパティで持たせるテスト –v1 各桁のインクリメント用のサブルーチンを作成し、ルールを各サブルーチン側でハードコーディングする(正しく動く) script spd property aList : {} property aRuleList : {{1, 2}, {1, 3}, {0, 1}, {1, 4}, {1, 8}} –各桁の{最小値, 最大値}ペアのリスト property aRuleLen : length of aRuleList end script set aList of spd to {} –initilaize set initNum to getMinNum() of me –本ルール下における最小値 set the end of aList of spd to initNum copy initNum to aNum repeat set aRes to incDigit(aNum, 1) of me if aRes = false then exit repeat end if set the end of aList of spd to aRes copy aRes to aNum end repeat –return length of (aList of spd) return (aList of spd) –与えられたルール下における最小値をルールリストから求める on getMinNum() –桁数が合っているだけのダミー数字を、適切な桁数作成する(例:11111) set tmpNumStr to "" repeat (aRuleLen of spd) times set tmpNumStr to tmpNumStr & "1" end repeat set tmpNum to tmpNumStr as integer –ルールから各桁の最小値を取り出して、各桁に設定する repeat with i from 1 to (aRuleLen of spd) set aDigNum to item 1 of item i of (aRuleList of spd) set tmpNum to setDigit(tmpNum, i, aDigNum) of me end repeat return tmpNum end getMinNum –繰り上がり処理(再帰呼び出しで使用) on incDigit(aNum, aDigit) set {thisMin, thisMax} to item ((aRuleLen of spd) – aDigit + 1) of (aRuleList of spd) set aTarget to getDigit(aNum, aDigit) of me if aTarget = thisMax then if aDigit = (aRuleLen of spd) then –オーバーフロー(桁あふれ)エラーを返す return false end if set bNum to incDigit(aNum, aDigit + 1) of me if bNum = false then return false set bNum to setDigit(bNum, aDigit, thisMin) of me else set aTarget to aTarget + 1 set bNum to setDigit(aNum, aDigit, aTarget) of me end if return bNum end incDigit –指定数値のうち指定桁の数字を返す on getDigit(aNum, aDigit) set aStr to aNum as string set aLen to length of aStr if aLen < aDigit then return false –エラー end if set tStr to character (aLen – aDigit + 1) of aStr return tStr as integer end getDigit –指定数値のうち指定桁の数字を返す on setDigit(aNum, aDigit, newNum) set aStr to aNum as string set aLen to length of aStr if aLen < aDigit then return false –エラー end if set aList to characters of aStr set item (aLen – aDigit + 1) of aList to (newNum as string) set aaStr to aList as string return aaStr as integer end setDigit |
FBEncryptorで文字列の暗号化、復号化
AppleScript名:FBEncryptorで文字列の暗号化、復号化 |
— Created 2016-02-16 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "FBEncryptorKit" –https://github.com/dev5tec/FBEncryptor set aStr to "ABCDEFあいうえお かきくけこGHIJKLMN" set aKey to "piyomaru" –Encryption set aEnc to (current application’s FBEncryptorAES’s encryptBase64String:aStr keyString:aKey separateLines:true) as string –> "N0/E5FB97DY+qOFtfKK9CCsAMKznyej94Ons1lC90V/9vMJIaBw5R+mbaxaTm711" –Decription set aDec to (current application’s FBEncryptorAES’s decryptBase64String:aEnc keyString:aKey) as string (* "ABCDEFあいうえお かきくけこGHIJKLMN" *) |
ファイルのMD5、SHA1、SHA512のハッシュ値を求める
AppleScript名:ファイルのMD5、SHA1、SHA512のハッシュ値を求める |
— Created 2016-02-11 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "md5Lib" –https://github.com/JoeKun/FileMD5Hash set aPath to POSIX path of (choose file) set a to (current application’s FileHash’s md5HashOfFileAtPath:aPath) as string –> "329e854b9993405414c66faac0e80b86" set b to (current application’s FileHash’s sha1HashOfFileAtPath:aPath) as string –> "50847286df61f304d142c6a0351e39029f010fc2" set c to (current application’s FileHash’s sha512HashOfFileAtPath:aPath) as string –> "5132a7b477652db414521b36……..1a6ff240e861752c" |
NSStringからSHA-3のハッシュ値を求める
AppleScript名:NSStringからSHA-3のハッシュ値を求める |
— Created 2017-08-09 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "SHA3Kit" –https://github.com/jaeggerr/NSString-SHA3 set origData to (current application’s NSString’s stringWithString:"hello") set aHash1 to (origData’s sha3:256) as string –> "1C8AFF950685C2ED4BC3174F3472287B56D9517B9C948127319A09A7A36DEAC8" set aHash2 to (origData’s sha3:224) as string set aHash3 to (origData’s sha3:384) as string set aHash4 to (origData’s sha3:512) as string |
NSDataからMD5値を計算する
AppleScript名:NSDataからMD5値を計算する |
— Created 2016-02-11 by Takaaki Naganoya — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "md5FromDataKit" –https://github.com/siuying/NSData-MD5 set aStr to "ぴよまるソフトウェア" set aNSStr to current application’s NSString’s stringWithString:aStr set aData to aNSStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aMD5Hex to (current application’s NSData’s MD5HexDigest:aData) as string –> "2d0b4e205f274f20b17dc8ca4870f1db" set aMD5 to (current application’s NSData’s MD5Digest:aData)’s |description|() as string –> <2d0b4e20 5f274f20 b17dc8ca 4870f1db> |
テキストをhexdump v4
AppleScript名:テキストをhexdump v4 |
— Created 2015-01-24 by Shane Stanley — Modified 2015-01-26 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" set aStr to "あいうえお" set theNSString to current application’s NSString’s stringWithString:aStr set aList to hexDumpString(theNSString) of me on hexDumpString(theNSString) set theNSData to theNSString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set theString to (theNSData’s |description|()’s uppercaseString()) –Remove "<" ">" characters in head and tail set tLength to (theString’s |length|()) – 2 set aRange to current application’s NSMakeRange(1, tLength) set theString2 to theString’s substringWithRange:aRange –Replace Space Characters set aString to current application’s NSString’s stringWithString:theString2 set bString to aString’s stringByReplacingOccurrencesOfString:" " withString:"" set aResList to splitString(bString, 2) –> {"E3", "81", "82", "E3", "81", "84", "E3", "81", "86", "E3", "81", "88", "E3", "81", "8A"} return aResList end hexDumpString –Split NSString in specified aNum characters on splitString(aText, aNum) set aStr to current application’s NSString’s stringWithString:aText if aStr’s |length|() ≤ aNum then return aText set anArray to current application’s NSMutableArray’s new() set mStr to current application’s NSMutableString’s stringWithString:aStr set aRange to current application’s NSMakeRange(0, aNum) repeat while (mStr’s |length|()) > 0 if (mStr’s |length|()) < aNum then anArray’s addObject:(current application’s NSString’s stringWithString:mStr) mStr’s deleteCharactersInRange:(current application’s NSMakeRange(0, mStr’s |length|())) else anArray’s addObject:(mStr’s substringWithRange:aRange) mStr’s deleteCharactersInRange:aRange end if end repeat return (current application’s NSArray’s arrayWithArray:anArray) as list end splitString |
TextEdit本文色に応じて青っぽい色は男性の音声で、赤っぽい色は女性の音声で読み上げ
TextEditの本文内で文字色が青っぽい色の文字は男性の音声で、赤っぽい色の文字は女性の音声で読み上げる(sayコマンド)AppleScriptです。
実行時には日本語読み上げ音声のKyokoとOtoyaをインストールしてある必要があります。インストールしてあるかどうか、対象の言語、性別で検出を行い、存在していなかった場合には読み上げを行いません。
AppleScript名:TextEdit本文色に応じて青っぽい色は男性の音声で、赤っぽい色は女性の音声で読み上げ |
— Created 2018-02-15 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" property NSColor : a reference to current application’s NSColor property NSArray : a reference to current application’s NSArray property NSSortDescriptor : a reference to current application’s NSSortDescriptor –TTS音声情報を取得する set curLang to "ja_JP" set v1List to getTTSVoiceNameWithLanguageAndGender(curLang, "Male") of me if length of v1List = 0 then return set v1 to contents of item 1 of v1List –Male Voice set v2List to getTTSVoiceNameWithLanguageAndGender(curLang, "Female") of me if length of v2List = 0 then return set v2 to contents of item 1 of v2List –Female Voice –TextEditの書類から情報を取得 set aResRec to (getTextStrAndColor() of me) set colList to colorDat of aResRec set strList to strList of aResRec set aLen to length of strList repeat with i from 1 to aLen set curColor to contents of item i of colList set curStr to contents of item i of strList set aColor to retColorDomainNameFromList(curColor, 65535) of me if aColor = "blue" then –Read by Male Voice say curStr using v1 else if aColor = "red" then –Read by Female Voice say curStr using v2 end if end repeat on getTextStrAndColor() tell application "TextEdit" if (count every document) = 0 then error "No Document" tell front document set colList to (color of every attribute run) set attList to every attribute run end tell return {colorDat:colList, strList:attList} end tell end getTextStrAndColor on retCocoaColorList(aColorList, aMax) set cocoaColorList to {} repeat with i in aColorList set the end of cocoaColorList to i / aMax end repeat set the end of cocoaColorList to 1.0 –Alpha return cocoaColorList end retCocoaColorList –数値の1D List with Recordをソート on sort1DRecList(aList as list, aKey as string, ascendingF as boolean) set aArray to NSArray’s arrayWithArray:aList set desc1 to NSSortDescriptor’s sortDescriptorWithKey:aKey ascending:ascendingF selector:"compare:" set bList to (aArray’s sortedArrayUsingDescriptors:{desc1}) as list return bList end sort1DRecList on getTTSVoiceNameWithLanguageAndGender(voiceLang, aGen) if aGen = "Male" then set aGender to "VoiceGenderMale" else if aGen = "Female" then set aGender to "VoiceGenderFemale" end if set outArray to current application’s NSMutableArray’s new() –Make Installed Voice List set aList to current application’s NSSpeechSynthesizer’s availableVoices() set bList to aList as list repeat with i in bList set j to contents of i set aDIc to (current application’s NSSpeechSynthesizer’s attributesForVoice:j) (outArray’s addObject:aDIc) end repeat set aPredicate to current application’s NSPredicate’s predicateWithFormat_("VoiceLocaleIdentifier == %@ && VoiceGender== %@", voiceLang, aGender) set filteredArray to outArray’s filteredArrayUsingPredicate:aPredicate set aResList to (filteredArray’s valueForKey:"VoiceName") as list return aResList end getTTSVoiceNameWithLanguageAndGender on retColorDomainNameFromList(aColList as list, aColMax as integer) set {rNum, gNum, bNum, aNum} to retCocoaColorList(aColList, aColMax) of me set aCol to NSColor’s colorWithCalibratedRed:rNum green:gNum blue:bNum alpha:aNum return retColorDomainNameFronNSColor(aCol) of me end retColorDomainNameFromList on retColorDomainNameFronNSColor(aCol) set hueVal to aCol’s hueComponent() set satVal to aCol’s saturationComponent() set brightVal to aCol’s brightnessComponent() if satVal ≤ 0.01 then set satVal to 0.0 set colName to "" if satVal = 0.0 then if brightVal ≤ 0.2 then set colName to "black" else if (brightVal > 0.95) then set colName to "white" else set colName to "gray" end if else if hueVal ≤ (15.0 / 360) or hueVal ≥ (330 / 360) then set colName to "red" else if hueVal ≤ (45.0 / 360) then set colName to "orange" else if hueVal < (70.0 / 360) then set colName to "yellow" else if hueVal < (150.0 / 360) then set colName to "green" else if hueVal < (190.0 / 360) then set colName to "light blue" –cyan else if (hueVal < 250.0 / 360.0) then set colName to "blue" else if (hueVal < 290.0 / 360.0) then set colName to "purple" else set colName to "pink" –magenta end if end if return colName end retColorDomainNameFronNSColor |
テキストのキーワード検索(ファイルから読み込んで検索。複数結果対応)
AppleScript名:テキストの複数検索(ファイルから読み込んで検索) |
— Created 2017-08-09 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" property NSString : a reference to current application’s NSString property NSMutableArray : a reference to current application’s NSMutableArray property NSDate : a reference to current application’s NSDate property NSLiteralSearch : a reference to current application’s NSLiteralSearch set aFile to POSIX path of (choose file) set a1Dat to NSDate’s timeIntervalSinceReferenceDate() set aStr to NSString’s stringWithContentsOfFile:aFile encoding:(current application’s NSUTF8StringEncoding) |error|:(missing value) set aRes to searchWordRanges(aStr, "子供") of me as list –> {{location:1159, length:2}, {location:1242, length:2}, {location:1261, length:2}, ….. set b1Dat to NSDate’s timeIntervalSinceReferenceDate() set c1Dat to b1Dat – a1Dat on searchWordRanges(aTargText as string, aSearchStr as string) set aStr to NSString’s stringWithString:aTargText set bStr to NSString’s stringWithString:aSearchStr set hitArray to NSMutableArray’s alloc()’s init() set cNum to (aStr’s |length|()) as integer set aRange to current application’s NSMakeRange(0, cNum) repeat set detectedRange to aStr’s rangeOfString:bStr options:(NSLiteralSearch) range:aRange if detectedRange’s location is equal to current application’s NSNotFound then exit repeat hitArray’s addObject:detectedRange set aNum to (detectedRange’s location) as integer set bNum to (detectedRange’s |length|) as integer set aRange to current application’s NSMakeRange(aNum + bNum, cNum – (aNum + bNum)) end repeat return hitArray end searchWordRanges |
テキストのキーワード検索(結果をNSRangeのlistで返す)
AppleScript名:テキストのキーワード検索(結果をNSRangeのlistで返す) |
— Created 2017-08-09 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" –http://piyocast.com/as/archives/4771 property NSString : a reference to current application’s NSString property NSMutableArray : a reference to current application’s NSMutableArray property NSLiteralSearch : a reference to current application’s NSLiteralSearch set aStr to "ATGC ACGT ATGC AGTC ATGC ACGT ATGC AGTC ATGC ACGT ATGC AGTC ATGC ACGT ATGC AGTC " set aRes to searchWordRanges(aStr, "ATGC") of me as list –> {{location:0, length:4}, {location:10, length:4}, {location:20, length:4}, {location:30, length:4}, {location:40, length:4}, {location:50, length:4}, {location:60, length:4}, {location:70, length:4}} on searchWordRanges(aTargText as string, aSearchStr as string) set aStr to NSString’s stringWithString:aTargText set bStr to NSString’s stringWithString:aSearchStr set hitArray to NSMutableArray’s alloc()’s init() set cNum to (aStr’s |length|()) as integer set aRange to current application’s NSMakeRange(0, cNum) repeat set detectedRange to aStr’s rangeOfString:bStr options:(NSLiteralSearch) range:aRange if (detectedRange’s location) is equal to (current application’s NSNotFound) then exit repeat hitArray’s addObject:detectedRange set aNum to (detectedRange’s location) as integer set bNum to (detectedRange’s |length|) as integer set aRange to current application’s NSMakeRange(aNum + bNum, cNum – (aNum + bNum)) end repeat return hitArray end searchWordRanges |