0

How can I trigger an applescript on mousedown? I want this applescript to run when a user doubleclicks on empty space in the desktop (i.e. not clicking on the icons present on desktop).

This is my script so far:

try
    set toggle to do shell script "defaults read com.apple.finder CreateDesktop"
    if toggle = "true" then
        do shell script "defaults write com.apple.finder CreateDesktop false"
    else if toggle = "false" then
        do shell script "defaults write com.apple.finder CreateDesktop true"
    end if
end try

do shell script "killall Finder"
delay 0.1
activate application "Finder"

1 Answer 1

1

Not sure the double click on empty space can be done, but I'm sure it would be kinder to ask the Finder to quit rather than kill it... Finders have feelings too ;-)

You could always save it as an app & put it in the Dock.

tell application "Finder" to quit
-- /*give it time, otherwise it will try to activate before it's quit & this simple version won't check if it relaunched.*/
delay 2 
try
    tell application "Finder" to activate
end try
--my testFinderRunning() --/*uncomment to add the belt & braces method*/

Add this routine to make sure it relaunched

    on testFinderRunning()
    set test to 0
    repeat while test = 0
        log test
        tell application "System Events" to set test to count (every process whose name is "Finder")
        delay 2
        --/*we do this even if active because it doesn't naturally come to front.*/
        try
            tell application "Finder" to activate
        end try
        if (test > 0) then exit repeat
    end repeat
end testFinderRunning

You can put the Applescript menu in the menu bar - http://thepoch.com/tumblr/enable-the-script-menu-in-mac-os-xs-menu-bar.html short version... launch Applescript, get Prefs, set 'Show script menu in menu bar'

That may allow you to assign Key Commands from System Prefs/Keyboard, but I haven't had time to test yet.

2
  • Thanks for the code. Would you by any chance know if I can show this app that I generated using applescript in the menubar? As an individual app, completely which I can trigger in the menubar like apps such as Caffeine.
    – Sushi
    Commented Aug 22, 2014 at 13:42
  • You can put the Applescript menu in the menu bar - thepoch.com/tumblr/… - whether that would then allow you to assign perhaps a key command, I haven't investigated. [part added to answer in case link vanishes]
    – Tetsujin
    Commented Aug 22, 2014 at 17:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .