Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to cycle between sets of Desktop items UNIX
I have long wanted a way to store and retrieve Desktop items. That is, change the items on my Desktop according to the task I'm currently working on -- dev, doc, design, surf. Well, I tried with some simple mv commands in Terminal, and it seemed to work fine. So I wrote a short script to handle this task.

I placed my script in ~/bin, and remember to make it executable (chmod 755 scriptname). The first time you run it, it will create a top-level storage directory in ~/Library/Desktops. It will then create a file named _current_ in that directory, which will contain the name of the "current" desktop items that are in ~/Desktop.

The first time the script is run, the "current" desktop item storage will be called "default." If the desktop script is run without any parameters, it will list the available storage names. The current one will be marked with >>. If a paramater is supplied to the script, it will either retreive the items from an existing storage bin, or create a new storage bin if none exists with that name.

I have only tested it on my PowerBook with 10.4, so I made 10.4 a requirement. I guess Spotlight is needed to get the update done in the Finder. I imagine that one should only use storage names with ordinary identifiers -- that is, they should start with a letter and not contain any spaces or other weird characters. I have not tested using non-standard names; the script would need some work to handle them properly, I think.

Warning!

I do not take any responsibility for this script and what it does. mv can be destructive so be careful. It hasn't broken anything for me yet, but I have only been using it for a couple of days. Usually I only make scripts for own usage -- I'm no expert in scripting, so if you can see any flaws or obvious mistakes, please add a comment.

[robg adds: I tested this on a Core Duo mini, and it seems to work just fine. It's an interesting idea, sort of like a simplified version of true virtual desktops.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[5,472 views]  

A script to cycle between sets of Desktop items | 15 comments | Create New Account
Click here to return to the 'A script to cycle between sets of Desktop items' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to cycle between sets of Desktop items
Authored by: paperwings on Jul 13, '06 07:41:08AM

This is probably the most interesting hint I've seen here in quite a while.



[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: jmgriff on Jul 13, '06 09:14:21AM

There used to be an application called Deviant that did more or less the same thing - it has now become a Quicksilver plugin AFAIK.

Some of the virtual desktop applications also allow you to switch desktop contents at the same time as desktops too.



[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: gregpare on Jul 13, '06 10:04:41AM

Yes, Quicksilver does do this with the Deviant plug-in. And, it's quite handy. It also doesn't move data around, but (from what I can tell) simply creates an desktop folder alias that points to whatever folder you want, and restarts the finder.

I've set up keyboard shortcuts (ctrl-0 thru ctrl-9 on the keypad) and it gives me 10 desktops use (with growl feedback when switching). I only wish there was a way to change the desktop picture at the same time.

I messed with creating an applescript to do the same thing, but gave up after a while. It didn't seem that hard, but I'm not much of an applescript user. If anyone comes up with a better solution, let me know.

I tried the software "You Control:Desktops" for a while, but I think it actually moves data around and that's just a little too scary for my taste.



[ Reply to This | # ]
sooo coool! thank you!
Authored by: nick on Jul 13, '06 09:26:23AM

nt.



[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: designr on Jul 13, '06 09:52:12AM

Just a thought... Instead of moving data around, couldn't you make 3 or 4 "Desktop" folders (i.e., Desktop 1, Desktop 2, etc.) and use the ln command to change which folder a "Desktop" alias points to?

ln [-fhinsv] source_file [target_file]

I used a similar strategy in an Applescript to switch between iTunes folders (a big 20 GB music library on my server and a small 4 GB music library on my laptop). I renamed my existing Music Folders to Local Music and Server Music and then created a symbolic link called "Music" which pointed to one or the other. The Applescript then toggled the symbolic link.

Because no data is actually moved, there is almost no time involved in switching and less risk.



[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: whenders0n on Jul 13, '06 11:17:04AM

heh sorry to dupe you below. you replied before i reloaded =)



[ Reply to This | # ]
Help?
Authored by: gregpare on Jul 13, '06 12:23:56PM

Anybody want to share more detailed examples on how to do this?

And, does anybody know if it is possible to change the desktop image in a script as well? I've been changing my desktops using deviant for a while, but it gets a little confusing knowing which desktop I'm using at a glance.



[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: designr on Jul 14, '06 08:36:19AM
Here's the script I used:

tell application "System Events"
  if not (exists application process "iTunes") then
    set short_name to do shell script ("id -un")
    tell application "Finder"
      if (exists folder "Music:ServerMusic:") then
        set the_path to POSIX path of file "Music:ServerMusic:"
        do shell script "ln -fhs '" & the_path & "' '/Users/" & short_name & "/Music'"
      else
        do shell script "ln -fhs '/Users/Shared/LocalMusic/' '/Users/" & short_name & "/Music'"
      end if
    end tell
  end if
end tell
tell application "iTunes" to activate
The two folders were "ServerMusic" on a server share called "Music" and "LocalMusic" in the /Users/Shared/ folder.

[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: whenders0n on Jul 13, '06 09:56:16AM

A safer way to do this would be to create symbolic links for the Desktop instead of moving things. So the script would only have to move things once, when it moves the Desktop to /Library/Desktops the first time you run it.



[ Reply to This | # ]
using 'mv' is a bad idea
Authored by: subdude on Jul 13, '06 10:53:40AM

'mv' does not respect resource forks (and IIRC, some file meta data). Use 'ditto' instead:

ditto --rsrc src_file dst_file



[ Reply to This | # ]
using 'mv' is a bad idea
Authored by: wallybear on Jul 14, '06 01:27:43AM

in Tiger mv will preserve resource forks.



[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: clh on Jul 13, '06 02:23:27PM

That's neat. How hard would it be to make a menubar icon or dock interface for this?



[ Reply to This | # ]
A script to cycle between sets of Desktop items
Authored by: DougAdams on Jul 14, '06 12:09:22PM
How hard would it be to make a menubar icon or dock interface for this?

Here, here. My vote is for a menulet. And incorporate the symlink tip mentioned above.

---
Doug's AppleScripts for iTunes
http://www.dougscripts.com/itunes/

[ Reply to This | # ]

A script to cycle between sets of Desktop items
Authored by: DougAdams on Jul 14, '06 11:59:56AM
in Tiger mv will preserve resource forks.

Now that is news to me. Hurrah!

---
Doug's AppleScripts for iTunes
http://www.dougscripts.com/itunes/

[ Reply to This | # ]

A script to cycle between sets of Desktop items
Authored by: sjk on Jul 14, '06 02:57:17PM
Preserving Spotlight (Finder) comments can be troublesome when using mv (et.al.) because they're saved in .DS_Store files.

[ Reply to This | # ]