Last active
February 20, 2016 09:55
-
-
Save szk-3/ce0770240ec1eecff3e0 to your computer and use it in GitHub Desktop.
Cocoaの機能を使ってdefaultsコマンドを実行するAppleScriptハンドラ ref: http://qiita.com/szk-3/items/7b23c77196ba8d26ed77
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use framework "Foundation" | |
my defaultsRead("com.apple.dock") | |
my defaultsWrite("com.apple.dock", {pinning:"start"}) | |
my defaultsDelete("com.apple.dock", {"pinning"}) | |
on defaultsRead(domain as text) | |
--require framework: Foundation | |
set defaults to current application's NSUserDefaults's standardUserDefaults() | |
return (defaults's persistentDomainForName:domain) as record | |
end defaultsRead | |
on defaultsWrite(domain as text, writeDictionary as record) | |
--require framework: Foundation | |
set defaults to current application's NSUserDefaults's standardUserDefaults() | |
set preferencesDictionary to (defaults's persistentDomainForName:domain)'s mutableCopy() | |
preferencesDictionary's addEntriesFromDictionary:writeDictionary | |
defaults's setPersistentDomain:preferencesDictionary forName:domain | |
my defaultsSynchronize() | |
end defaultsWrite | |
on defaultsDelete(domain as text, deleteKeys as list) | |
--require framework: Foundation | |
set defaults to current application's NSUserDefaults's standardUserDefaults() | |
set preferencesDictionary to (defaults's persistentDomainForName:domain)'s mutableCopy() | |
preferencesDictionary's removeObjectsForKeys:deleteKeys | |
defaults's setPersistentDomain:preferencesDictionary forName:domain | |
my defaultsSynchronize() | |
end defaultsDelete | |
on defaultsSynchronize() | |
--require framework: Foundation | |
set success to current application's NSUserDefaults's standardUserDefaults()'s synchronize() | |
if not success then | |
error "Synchronization in NSUserDefaults has failed" | |
end if | |
end defaultsSynchronize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults read com.apple.dock | |
defaults write com.apple.dock pinning -string start | |
defaults delete com.apple.dock pinning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment