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


Click here to return to the 'Applescript: PathLabeller' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Applescript: PathLabeller
Authored by: sinjin on Nov 24, '04 01:03:54AM
I like seeing stuff from people thinking differently. Nice, simple idea. Don't predict I'll need it, but thanks for the opportunity to practice some Applescript (use it or lose it!).

Here is the script in about as simple a form as I could imagine. No input or conditionals. I suspect you could change the variables in Script Editor as needed or save a few copies for different labels and directories (or add in your own dialog/conditionals) and run it from a launcher, script menu or a contextual menu plug in). It will change the labels of every folder up to but not including the top most folder (this made sense to me, the top most would be the starting point so no need to label it).


tell application "Finder"
	set thisItem to selection as alias
	set topMostFolder to "some folder" --Name of the top most folder
	repeat until the name of thisItem is topMostFolder
		set the label index of thisItem to 2 --label value, 0 is no label
		set thisItem to container of thisItem as alias
	end repeat
end tell


[ Reply to This | # ]
Applescript: PathLabeller
Authored by: sinjin on Nov 24, '04 01:51:52AM
Aw hell, it this turned out to be too much fun! Here it is with a "toggle" like action and dialog. This really flies if you use use a launcher app (e.g. Launchbar or Butler). A couple of keystrokes and your whole path lights up or turns off depending on its state

tell application "Finder"
	set thisItem to selection as alias
	set topMostFolder to "1.Work" --Name of the enclosing folder
	if the label index of thisItem is greater than 0 then
		set labelNum to 0
	else
		set labelNum to 2
	end if
	display dialog ¬
		"Path labeller" & return & return & ¬
		"Enter the label value (0-7):" default answer labelNum buttons {"Cancel", "Label"} default button 2
	copy the result as list to {labelNum, button_pressed}
	if button_pressed is "Label" then
		set labelNum to labelNum as integer
		repeat until the name of thisItem is topMostFolder
			set the label index of thisItem to labelNum
			set thisItem to container of thisItem as alias
		end repeat
	end if
end tell


[ Reply to This | # ]
Applescript: PathLabeller
Authored by: dogboy on Nov 24, '04 05:22:12AM

Awesome. I use Launchbar too. Thanks.



[ Reply to This | # ]
Applescript: PathLabeller
Authored by: osxpounder on Nov 24, '04 01:17:39PM

Thanks for the groovy script. Have you put it through its paces yet--chosen every label? I get weird probs when I run it:

If I choose 1, I actually get Orange, the label that should be number 2.

If I choose 2, I actually get Red, the label that should be number 1.

If I choose 3, I get Yellow, the proper label.

If I choose 4, I actually get Blue, the label that should be 5.

If I choose 5, I actually get Purple, the label that should be 6.

If I choose 6, I actually get Green, the label that should be 4.

If I choose 7, I actually get Gray, the proper label.

No matter what I choose, the script always stops with an error. It labels the entire path, but after doing so, it stops with an error.

I'm not using a launcher app. Instead, I saved the script as an application [no startup screen] and put its alias on my Finder toolbar. I also tried running it directly from Script Editor, first. Results are the same, either way.

The label mismatches are a bit weird, but workable. Is there any way I can stop the script from ending with that error, though?

---
--
osxpounder



[ Reply to This | # ]
Applescript: PathLabeller
Authored by: osxpounder on Nov 24, '04 02:27:15PM

Heh, I figured out why I get the error message: I need to replace "1.Work" in your script with the name of the topmost folder on my own Mac, which, for my purposes, will be "Documents".

Still have no idea why the colors/labels are shuffled around, though.

Now I'm going to graft a dialog box onto this script to remind me that the color choices are mixed up. @whee!

---
--
osxpounder



[ Reply to This | # ]
Applescript: PathLabeller
Authored by: sinjin on Nov 24, '04 02:49:15PM
Glad you like it!
Heh, I figured out why I get the error message: I need to replace "1.Work" in your script with the name of the topmost folder on my own Mac, which, for my purposes, will be "Documents".
Yup. If you don't name the top most folder correctly it will try to keep labelling up to the root level of your drive and reach and error when it can't get any further. Sorry I wasn't more clear that you needed to change it!

The script is pretty bare (no error trapping, etc) so one could add dialogs and handlers to deal with user "mistakes" if they wanted to make it more accessible to others. For example, the script will die if you enter anything other than 0 through 7. With coersion and "try" handlers you could get it to kick back to the user for a valid label entry. You could even get it to accept text (e.g "Red") instead of numbers to be more intuitive, which gets me to your next problem...

Still have no idea why the colors/labels are shuffled around, though.
That isn't an error. For whatever reason the order you see the labels listed in contextual menus does not match their numerical order! There is probably a "legacy" reason for the integer value while the order in the menu is more pleasing to the eye, or something like that.

[ Reply to This | # ]