I’m getting an errors in the last version. Something like "can’t get item 8 (or 10) of {some list items}. Tried to trap the error, but couldn’t. So, maybe it’s happening in the other script?
BTW, all I did was add a simple comparison timer with Python and the error block.
it’s strongly recommended to never use relative paths (path to .) in properties.
In some environments e.g. saving the script as application the values are persistent and the script will fail on other computers.
PS: the keyword its as a reference to the parent object in a tell block in ONLY needed if the terminology is ambiguous in the same application. In this script it’s just syntactic sugar like the
tell its the first Finder window to set the L to {its the id, its the target as text}
this does exactly the same
tell first Finder window to set L to {id, target as text}
Hello, I really have no idea, I assume you have deleted the old “net.mcusr.treevals” as I explained you had to do it.
I run the toolbar-applet here, and it works flawlessly. Maybe you should try to run it from the editor, and see what goes wrong there?
You may also want to either overwrite or rename the old version, or add a short-version string to the property list file, to assure that it is indeed the latest version that runs, especially since the contents of the net.mcusr.treevals script object aren’t compatible between the two versions.
I hope you figure out whats wrong.
@ Stefan: Syntactic sugar is nice, as long as it isn’t overdone, the its finder window, is really overdoing, and I’m going back to fix it!
I will also consider the relative paths in scripts, should I distribute in compiled form. Thanks for the reminder.
On the side. A strange thing just happened if I remember right. I ran a compiled script from the Script Editor with ‘run script’ and it kept displaying “1”.
property x : 0
set x to x + 1
tell application "System Events"
display dialog x
end tell
Then I ran it with this from the Script Editor:
set desk_path to (path to desktop) as string
set pp to POSIX path of (desk_path & "IncX.scpt")
do shell script "osascript " & (quoted form of pp)
and the property value was saved from then on. I think this is strange.
The toolbar-applet in post #12 is fixed and updated.
I got the same error as well, I chose a “wrong handler” for finding the index of the item obviously. I could have had made something more sophisticated than what I have put into it now, but I think it will suffice.
The error was, that the list consisting of two items, would end up on two different lines, leading to the index of items, which the previous indexOfItem handler returned, gets out of sync. (The handler is really meant for only one item in each element of the list, no sublists). I started to use the previous handler, when I had the idea of coercing the items into text, well, I deviated from that scheme, but kept the handler.
Know everything should work as it is supposed to, with the correct handler and without superfluos circumloitions of syntactic sugar.
You really should return from a script, in order to get the property saved with it, but I think your problem with the property is strange too.
set f to choose folder
tell application "Finder"
activate
open f
tell front window
set current view to list view
end tell
end tell
ignoring application responses
tell application "System Events"
keystroke "a" using command down
delay 1
key code 124 using {command down, option down, shift down}
end tell
end ignoring
This my simple version. The other versions don’t work a anymore for some reason.
I am sorry to hear that, well, anyway, I have followed Stefan’s instructions about not using properties for storing a copy, and I zipped it, and put it into my dropbox, it can be found here should you be interested. You must doublecilick on it from finder to make it register with launchservices, when the applet is placed in its destination.
Edit
I’ll find a a way to track if finder is busy, and bail out with a message about “please try again later”, if it is. I won’t post it, before I have a readme file ready.
I have updated the script in post #12 once again with a handler that checks if finder is busy before the button gets hit, I have also updated the zipfile with the applet to include a small, but hopefully sufficient readme file.
PS. If you made the first version, and have not followed the thread, and have installed the latest version, and experienced that something doesn’t work, be sure to delete the file ~/Library/Caches/TemporaryItems/net.mcusr.treevals and try again .
I added a shell script to invoke tree.app from the commandline, showing a tree of the current directory, if the window showing the current working directory is expanded, it becomes contracted.
I have updated it once more: Changed from activation of finder to selecting its first window, in order to leave the screen as stable as possible. I had suddenly windows popping up on my second monitor, while the toolbar-applet ran.
I promise this is the last version, the link above should still work for getting this.
I have added code to tell that the applet indeed works, this may be to your taste, or not:
tell application id "MACS"
set uIconPath to POSIX path of (path to resource "Finder.icns")
do shell script "qlmanage -p " & uIconPath & " >/dev/null 2>&1 & sleep 0.3 ; kill -9 $!"
end tell
The slow tops command, that needed a delay of 1 second to perform a sample of cpu usage in the start really bugged me, so I found a way to let ps handle it, alot faster.
ps -ArmC -O %cpu
is the incatation that delivers with haste.
There can’t be more to add, nor to subtract by now!
I downloaded your tree script and it’s working great. Very fast and helpful finding which branch to go to. That icon is nice. I didn’t expect it to work perfectly short of turning off everything else in the Finder.
Thank you too! I am actually thinking of trying to change icons runtime, and getting some “3-D” icons, so it seems to have a button pushed in while it runs. (It will be tough getting rid of the Finder-face though. :))
I’ll at least try to change icons runtime, soon, and we’ll see.
The caveat is if the user tries it on a folder that is too deeply nested, and has to restart Finder, then the icon will be wrong, until he/she runs it again. I can’t evade running this on a single thread, or Finder won’t respond correctly to the fictive keystrokes, or so I think. It is another experiment that has to be done as well.
Edit
It is also a question of how much time is going to be spent on changing that icon.
The scheme is to have an isrunning variable in the script, and start out by invoking a helper appliction, that may change the icon file in the parent, and update its version property, before it in turns calls the parent via open -new instance of parent, which in turn runs the run handler of the parent, but which will quit instantly, since the isRunning is true. What we have achieved by then, is hopefully to have reregistered the application, and forced Finder to update the icon on the toolbar.
The idea is of course to keep the button pressed, while it is working, and let it go back up again, when the toolbar-applet is done working, and not to display the “expandedness” of the folder, which would come out of sync quickly.
I actually figured out a “re-entrant” scheme for the applet to change the icon on the finders toolbar, but that does only help so much, as for changing the icon of the applet, as I can’t seem to figure out a way to make the toolbar of Finder to update. (Just try for yourself manually).
So, the other option is of course to use StefanK’s progress bar, but I am reluctant to do that, since the times for expanding/contracting a folder varies so wildly.
So, it ends here, shouldn’t anybody have some better ideas.
It’s still working great and Haven’t had any errors. The tree icon in the toolbar hasn’t changed yet. Just expanded the home folder and it only took a few seconds for 2500+ items! Also, there’s no need for a progress item, you can see that the script is working in the status bar at the bottom.
Editted: I take that back. It’s starting to hang and doesn’t unexpand. I’ll try and see what’s going on. Think I understand your script now. One thing I don’t understand is the "qlmanage’ shows up in the menu bar next to the Apple when it hangs. Don’t know where that comes from.
Now it’s working again. It might have fixed itself when I reinstalled the icon in the toolbar. However, I did do other maintenance, because the internet is not working very well today.
Hello kel.
That was what I was talking about, It seems to me, that the icon that were with the app, stays pretty much fixed, until I drag it off the Finders toolbar, and relocates the app there again, with a new icon.
What I wanted to do, was to have two icons, and “simulate movement” by switching between two 3-d icons, so you got the feeling of pushing a knob. (like some of the stuff that ships with Finder).
Well, I had to abandon that idea. And it works great for me too, I use it (alot) when I navigate tree-structures, like bundles, and packages, and expanded zip files. I can’t recall having had the last version crash yet.