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


Click here to return to the 'A file-gathering AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A file-gathering AppleScript
Authored by: ceffe on Oct 15, '04 05:45:35PM

I love this script. However, it does not seem to work for files on my desktop. Does anyone know how to make it work for files on the desktop, without having to open a finder window for doing the operation? For me, the desktop is the place where I most often could have great use for this kind of tidying script.
/ceffe



[ Reply to This | # ]
A file-gathering AppleScript
Authored by: ramonf on Oct 15, '04 09:12:49PM

Change set theLocation to the target of Finder window 1 to

try
set theLocation to the target of Finder window 1
on error
set the theLocation to desktop
end try

and delete select newFolder (this was there to return focus to the finder window on System 9, if I remember right)



[ Reply to This | # ]
A file-gathering AppleScript
Authored by: ceffe on Oct 16, '04 07:19:03AM

Thanks. It works better with these adjustments. However, the new code does not work as intended if a finder window is open, albeit inactive. In those cases the new folder is created within the folder of the inactive finder window rather than on the desktop.
/ceffe



[ Reply to This | # ]
A file-gathering AppleScript
Authored by: ramonf on Oct 16, '04 01:33:07PM

I see the problem, sorry. Now, the solution I propose makes the behaviour somewhat inconsistent. There are now two cases:

  1. If the files to be gathered are in different folders, which can happen in a selection made on a window in list view, then the new folder will be made in the Finder's frontmost window.
    Notice that in this case I have handled idiosyncratically (or idiotically) the situation in which more than one file or folder has the same name. If this happens the script moves some files but not others, the alternative (which would require some more coding) is to alert the user and do nothing.
  2. If the files to be gathered are in the same folder then the new folder will be created in that folder. This will cover the cases in which the selection is on the desktop or in a window in icon view.
    Notice that in this case the script will not handle well the situation in which the new folder has the same name as one of the items being gathered (a fix would be to give it initially a temporary name, move the files and then rename the new folder). Right now it will tell you that the name is already taken.

The changes to be made to the original script are:

  1. Change
    
    set listNames to {}
    repeat with listItem in theList
    	set listNames to listNames & {basename(the name of listItem as string)}
    end repeat
    
    set listNames to sort(listNames)
    
    to
    
    set listNames to {}
    set listParents to {}
    repeat with listItem in theList
    	set listNames to listNames & {baseName(the name of listItem as string)}
    	set listParents to listParents & {the parent of listItem as string}
    end repeat
    
    set listNames to sort(listNames)
    set listParents to sort(listParents)
    
    set soleParent to (count listParents) = 1
    
  2. Change set theLocation to the target of Finder window 1 to
     
    if soleParent then
    	set theLocation to the parent of item 1 of theList
    else
    	set theLocation to the target of Finder window 1
    end if
    
  3. Delete select newFolder.
  4. Change " | sort -f" to " | sort -f -u" in the sort procedure.

A much more elegant fix would be possible if I knew a way of knowing if the selection is on the desktop proper or on a window for the desktop.



[ Reply to This | # ]
A file-gathering AppleScript
Authored by: ceffe on Oct 17, '04 07:17:11AM

Impressing! Thanks, this fully sorts the problem I was having. Now it is a nifty time-saver for tidying my desktop (as well as messy folders). I even dragged an app-version of this script to the finder toolbar for easy access when in folder windows.
Thanks again,
ceffe



[ Reply to This | # ]
A file-gathering AppleScript
Authored by: szabesz on Oct 18, '04 12:11:02PM

Ooops. This version has created a folder and moved my Desktop folder into it when running the script from the Desktop folder and clicking on the "Enter your own" button. Then nothing happened. I had to move back my Desktop folder to its place as root, since the Finder allowed me only to copy it back, but it was using the original one in the folder created by the script!

I do not have time to check the code why it does so, but I want to warn everybody!



[ Reply to This | # ]