views:

1036

answers:

1

I want to program my mouse button to show/hide the Finder. I wrote the following AppleScript and bound it to my mouse button:

tell application "System Events"
    --When this script is run,
    --  the frontmost application will be this script itself
    --Get the name of this script as it is running and hide it,
    --  so that the previous frontmost application is in front again
    set theName to name of the first process whose frontmost is true
    set visible of process theName to false

    set theName to name of the first process whose frontmost is true
end tell

if theName is "Finder" then

    tell application "System Events"
        set visible of process "Finder" to false
    end tell


else

    tell application "Finder"
        activate
    end tell

end if

This works, but is rather slow. It takes about 2 seconds to run.
I want it to be faster. The first tell block uses System Events to get the name of the script and hide it. Is there an easier/faster way to get the name of the frontmost application before the script starts? (i.e. the application that was active when the script was activated)

+2  A: 

The reason for the slow run time is that I saved the applescript as an Application. This makes the application PPC-only so it must run under Rosetta. If you choose Application Bundle, it will make a universal application.

hekevintran