Skip to content

Instantly share code, notes, and snippets.

@szk-3
Last active February 20, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szk-3/ce0770240ec1eecff3e0 to your computer and use it in GitHub Desktop.
Save szk-3/ce0770240ec1eecff3e0 to your computer and use it in GitHub Desktop.
Cocoaの機能を使ってdefaultsコマンドを実行するAppleScriptハンドラ ref: http://qiita.com/szk-3/items/7b23c77196ba8d26ed77
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
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