Showing posts with label Mac OS X. Show all posts
Showing posts with label Mac OS X. Show all posts

Friday, October 16, 2009

TIP:Applescript to invoke All Windows function of Exposé and bind it to key you please

Here is the applescript to invoke the All Windows function of Exposé :
on run
-- delay is needed so that keybindings defined in
-- tools like Fastscripts works
delay 0.1
tell application "System Events"
-- 101 is key code for F9 key
key code 101
end tell
end run
Assuming you have bound Exposé:All Windows function to F9 key.

So you say - what is the big deal?

Well, if you look at System Preferences... > Exposé and Spaces pane > Exposé Tab , you will see that it allows you to bind various functions to limited set of keys. The script enables you to bind it to any key such as Option+Tab. How? Heres how:

Save the above script in ~/Library/Scripts/Expose.app . Then bind it to Option+Tab using Quicksilver or Launchbar or Fastscripts.

Saturday, October 03, 2009

Un-minimize minimized windows and bring them to front using Applescript

While implementing the AWS tool that I talked about in the last post - I learned a cool new Applescript technique to unminimize minimized windows. Here it is:

-- assuming you have name of a minimized window
set theWindowName to ....

-- is it minimized?
if (value of attribute "AXMinimized" of window theWindowName is true) then
-- first un-minimize the window
value of attribute "AXMinimized" of window theWindowName to false
end if

-- raise it
perform action "AXRaise" of window theWindowName

I had not much documentation on attributes such as "AXMinimized" and perform action "AXRaise".

Thursday, January 01, 2009

Copy paths of selected items in Mac OS X Finder to clipboard

copypaths.app

(*
Script: copypaths.app

This script sets the clipboard to the paths of items selected in Finder window.
If there is no selection the clipboard is set to the path of the target
of the Finder window.

Installation:

1. Paste this script in Script editor
2. Save it as an application - ~/scripts/finder/copypaths.app
3. Drag and drop copypaths.app onto the Finder widow toolbar.

@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
tell application "Finder"
set paths to ""
set selected to selection
if (count of selected) is 0 then
set paths to POSIX path of (target of front window as alias)
else
repeat with aPath in every item in selected
set aPathString to POSIX path of (aPath as alias)
if paths is "" then
set paths to aPathString
else
set paths to paths & "
" & aPathString
end if
end repeat
end if
if paths is not "" then
set the clipboard to paths as text
end if
end tell

Go to parent folder in Mac OS X Finder

up.app

(*
Script: up.app

This script sets the target of the Finder window to the
parent of the current target of the Finder window.

Installation:

1. Paste this script in Script editor
2. Save it as an application - ~/scripts/finder/up.app
3. Drag and drop up.app onto the Finder widow toolbar.

@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
tell application "Finder"
set target of front window to (parent of target of front window)
end tell

Keep Mac OS X Finder and Terminal in sync

findercd.scpt

(*
Script: findercd.scpt

This script sets the target of the front window of Finder
to the directory path passed as the first argument. If
there is no Finder window, one is created. Optionally
the finder window can be activated by passing in "true"
as second argument. If no argument is passed
the user is prompted to select a directory
to go to.

The following two bash functions can be used to
invoke this script from bash running in Terminal
window:

# Change the directory of front window of
# Finder to pwd of shell
fcd() {
cd "${1}"
osascript ~/scripts/finder/findercd.scpt "`pwd`" ${2}
}

# Change the directory of front window of
# Finder to pwd of shell and activate the
# Finder window
fcda() {
fcd "${1}" true
}

Installation:

1. Paste this script in Script editor
2. Save it as a script - ~/scripts/finder/findercd.scpt
3. Add the fcd() and fcda() functions mentioned above
to your .bashrc or .bashrc_profile

This script complements the terminalcd.scpt script.

@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
on run argv
if (count of argv) is 0 then
try
set directory to POSIX path of (choose folder with prompt "Go to")
on error
return
end try
else
set directory to (item 1 of argv)
end if
set doActivate to false
if (count of argv) is greater than 1 then
set doActivate to (item 2 of argv)
end if
tell application "Finder"
if (count of windows) is 0 then
make new Finder window
end if
set target of front window to (POSIX file directory)
if doActivate = "true" then
activate
end if
end tell
end run

terminalcd.app

(*
Script: terminalcd.app

This script sets the directory of the shell in front window of Terminal to the
target directory of front window of Finder. If there is no Terminal window
is there a new window is created. If the the front window of
Terminal is busy new window is created.

Installation:

1. Paste this script in Script editor
2. Save it as an application - ~/scripts/finder/temrinalcd.app
3. Drag and drop terminalcd.app onto the Finder widow toolbar.

This script compliments the findercd.scpt script.

@author Sandip V. Chitale
@version 1.0
@date 1/1/2009
*)
tell application "Finder"
if (count of windows) is greater than 0 then
set cdTo to POSIX path of (target of front window as alias)
set terminalWasRunning to false
tell application "System Events"
if exists process "Terminal" then
set terminalWasRunning to true
end if
end tell
tell application "Terminal"
activate
if (count of windows) is 0 then
do script ""
else if window 1 is busy then
do script ""
end if
do script "cd '" & cdTo & "'" in front window
end tell
end if
end tell