views:

218

answers:

1

Hi Everyone:

I am wondering if there is some way that I can create an script on Mac OS X that will change the default save location of all native Cocoa apps. I don't know where to start, so I am open to any advice about how to do this.

Thanks for any help!

+3  A: 

Set the default directory for all applications that did not launch before:

defaults write NSGlobalDomain NSNavLastRootDirectory "~/Desktop"

Overwrite all previous locations for applications that did launch before:

find ~/Library/Preferences -name "*.plist" -exec grep -l NSNavLastRootDirectory {} \; | while read domain; do domain=${domain%.plist} ; defaults write "$domain" NSNavLastRootDirectory "~/Desktop"; done

In both cases, replace "~/Desktop" with your path. If it contains spaces or the tilde, don't forget to use quotes.

Nikolai Ruhe
Thanks Nikolai. Works great! However, Terminal does give me the following errors: Unexpected argument ~/Desktop; leaving defaults unchanged. 2009-08-18 12:18:41.353 Unexpected argument NSNavLastRootDirectory; leaving defaults unchanged. Unexpected argument 2; leaving defaults unchanged. Unexpected argument NSNavLastRootDirectory; leaving defaults unchanged. Is this normal? Also, I assume there isn't a way to change the location if the application has already opened...
PF1
I fixed the bug you encountered (due to spaces in application identifiers in your Preferences directory). Plus, I added preferences for applications that did not launch before. Now you can decide if you want to alter the path for all or only those, that did not launch before.
Nikolai Ruhe
Thanks Nikolai, I really appreciate the help! So I assume that my assumption was correct about not being able to change the launch location on currently open apps - completely fine, but I was just checking.
PF1
I can't think of a an easy way to affect open applications since a running process had to sync its preferences. It could be possible using some kind of code injection, bat I don't want to get my fingers dirty on that.
Nikolai Ruhe