2014-10-20 57 views
2

我正在玩一些「默認寫」my dotfiles &可以找到一種方法來寫六進制值。如何使用默認值在OS X上使用-data寫入hexa值?

當我讀我得到這樣的

$ defaults read com.ragingmenace.MenuMeters CPUSystemColor 
<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 6666831b 677c3f00 83d70ea8 3d0186> 

於是,我就沒有成功這個命令(檢查man defaults後)

$ defaults write com.ragingmenace.MenuMeters CPUSystemColor -data "<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 66668364 79783f83 1b677c3f 83bf8073 3f0186>" 
Command line interface to a user's defaults. 
Syntax: 

'defaults' [-currentHost | -host <hostname>] followed by one of the following: 

    read         shows all defaults 
    read <domain>      shows defaults for given domain 
    read <domain> <key>     shows defaults for given domain, key 

    read-type <domain> <key>    shows the type for the given domain, key 

    write <domain> <domain_rep>   writes domain (overwrites existing) 
    write <domain> <key> <value>   writes key for domain 

    rename <domain> <old_key> <new_key> renames old_key to new_key 

    delete <domain>      deletes domain 
    delete <domain> <key>    deletes key in domain 

    import <domain> <path to plist>  writes the plist at path to domain 
    import <domain> -     writes a plist from stdin to domain 
    export <domain> <path to plist>  saves domain as a binary plist to path 
    export <domain> -     writes domain as an xml plist to stdout 
    domains        lists all domains 
    find <word>       lists all entries containing word 
    help         print this help 

<domain> is (<domain_name> | -app <application_name> | -globalDomain) 
       or a path to a file omitting the '.plist' extension 

<value> is one of: 
    <value_rep> 
    -string <string_value> 
    -data <hex_digits> 
    -int[eger] <integer_value> 
    -float <floating-point_value> 
    -bool[ean] (true | false | yes | no) 
    -date <date_rep> 
    -array <value1> <value2> ... 
    -array-add <value1> <value2> ... 
    -dict <key1> <value1> <key2> <value2> ... 
    -dict-add <key1> <value1> ... 

你可以看到格式似乎無法識別。 所以一些變化沒有成功

$ defaults write com.ragingmenace.MenuMeters CPUSystemColor -data <040b73747265616d747970656481e803840140848484074e53436f6c6f72008484084e534f626a656374008584016301840466666666836479783f831b677c3f83bf80733f0186> 
# same error as the first one 

$ defaults write com.ragingmenace.MenuMeters CPUSystemColor -data "<040b73747265616d747970656481e803840140848484074e53436f6c6f72008484084e534f626a656374008584016301840466666666836479783f831b677c3f83bf80733f0186>" 
# same error as the first one 

$ defaults write com.ragingmenace.MenuMeters CPUSystemColor -data <040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 66668364 79783f83 1b677c3f 83bf8073 3f0186> 
zsh: parse error near `\n' 

$ defaults write com.ragingmenace.MenuMeters CPUSystemColor -data <'040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 66668364 79783f83 1b677c3f 83bf8073 3f0186'> 
zsh: parse error near `\n' 

任何想法如何得到這個工作?

回答

1

這很簡單,只需刪除<,> &所有空格。

$ defaults write com.ragingmenace.MenuMeters CPUSystemColor -data "040b73747265616d747970656481e803840140848484074e53436f6c6f72008484084e534f626a656374008584016301840466666666836479783f831b677c3f83bf80733f0186" 

您可以驗證它的工作做一個defaults read

$ defaults read com.ragingmenace.MenuMeters CPUSystemColor 

< 040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 6666831b 677c3f00 83d70ea8 3d0186>

+0

如果我有也使用'-array-add'參數?用哪一個命令添加一個xml字符串? – 2017-04-03 08:34:24