Remove this ad
avatar

ericn

superstar

Posts: 284

Lead

Apr 20 10 3:51 PM

Tags : :



Originally Posted by EricN on October 5, 2009 at 5:34pm

I remember the first time that I accidentally invoked Front Row — Apple’s full screen media player — on my Modbook. Since Front Row suppresses mouse actions and the on-screen keyboard, I was forced to go through the house looking for a hardware keyboard so that I could hit the escape key. Since Abracadabra seems to work in Front Row, my first response was to make a gesture for the escape key (key code 53). Unfortunately, using the standard approach


tell application "System Events" to key code 53


doesn’t work. Front Row just ignores the escape key when it is sent this way. You must instead


tell application "System Events" to tell "Front Row" to key code 53


There are a variety of full screen applications and some dialog boxes that will, like Front Row, ignore keystrokes sent the traditional way. If you want to use Applescript to send a keystroke in one these situations, you must first identify the application (by name) and then tell “System Events” to tell the application to send the key stroke. An AppleScript to do this and send an escape looks like:


-- Identify frontmost application 

set runningApps to "" as string 


set frontmostApp to "" as string 

tell application "System Events" 

 set runningApps to the name of every process whose background only is false 

 repeat with p in runningApps 

 if process p is frontmost then 

 set frontmostApp to p 

 exit repeat 

 end if 

 end repeat 

end tell 


-- Send keystroke 

tell application "System Events" 

 tell process frontmostApp to key code 53 

end tell


This is the AppleScript I have associated with my escape gesture:



Since I occasionally need to send a carriage return in situations like this, my AppleScript for my carriage return gesture (key code 36)


is similar. (Replace ‘key code 53’ with ‘key code 36’ in the above script.)



Update: Dec. 31, 2009. After assisting someone in setting up Quicksilver with Abracadabra, I realize that I've failed to mention something important. In order to use AppleScripts that involve GUI scripting (as most of my AppleScript do), one must enable access for assistive devices. Simply open System Preferences and click on the Universal Access preference pane. Then, make sure the box for "Enable access for assistive devices" at the bottom is checked.

Reply to This


 Reply by EricN on October 22, 2009 at 9:57pm


Those who like to fool around with the keyboard F-keys have probably stumbled across my favorite keyboard trick: Following the shortcut for Spaces (typically F8) with the shortcut for Exposé (F10). This exposes all the windows on each of the Spaces desktops. It is a cool and very useful trick.


So, naturally one of the first Abracadabra gestures I installed was this Spaces-Exposé trick:



This is a simple AppleScript type gesture with the following AppleScript code:


tell application "System Events"

key code 100 --F8 Spaces

key code 109 --F10 Expose All windows

end tell


See my second Pen Gesture blog article for more details on installation.


EricN


[Incidentally, if you follow a F8-F10 sequence with Command-1, the windows are ordered alphabetically by window title; whereas, if you follow with Command-2, the windows are ordered by application.]



Reply by EricN on November 2, 2009 at 9:26pm


Here is simple AppleScript borrowed from the MacRumors site to toggle the Ink window on and off. Attach it to your favorite gesture.


try

tell application "InkServer" to quit

end try


set inkWinState to (do shell script "/usr/bin/defaults read com.apple.ink.framework inkWindowVisible")


if inkWinState is equal to "0" then

do shell script "/usr/bin/defaults write com.apple.ink.framework inkWindowVisible -boolean Yes"

else if inkWinState is equal to "1" then

do shell script "/usr/bin/defaults write com.apple.ink.framework inkWindowVisible -boolean No"

end if


try

tell application "InkServer" to activate

end try



Reply by EricN on November 7, 2009 at 2:14pm


Occasionally, I need to make the wide assortment of files that 0SX keeps hidden temporarily visible. (This has become more important recently since I started using ExanDrive to connect to an sftp (ssh) server.) What I need is a simple way to toggle back and forth between files hidden and files visible. So I made a gesture for that.


to which I attached the AppleScript:


try

set ShowAllFiles to do shell script "defaults read com.apple.finder AppleShowAllFiles -bool" as boolean

on error

set ShowAllFiles to false

end try


if ShowAllFiles is true then

do shell script "defaults delete com.apple.finder AppleShowAllFiles;killall Finder"

else

do shell script "defaults write com.apple.finder AppleShowAllFiles -bool YES;killall Finder"

end if

EricN



Reply by EricN on November 17, 2009 at 7:15pm


Since I often use the erasure end of my stylus to make gestures and since I can only do that if the normal erasure behavior is turned off, I need a fast convenient way to turn the erasure on and off. Well ... there is a gesture for that:


and an associated AppleScript:


tell application "System Preferences"

activate

reveal pane "Pen Tablet"

end tell


delay 0.5

try

tell application "System Events" to tell process "System Preferences" to tell window "Pen Tablet" to tell tab group 1 to tell checkbox "Enable Eraser" to click

on error

tell application "System Events" to key code 76

delay 2.5


tell application "System Events" to tell process "System Preferences" to tell window "Pen Tablet (32-bit)" to tell tab group 1 to tell checkbox "Enable Eraser" to click

end try


tell application "System Preferences"

quit

end tell


If you use your Modbook in different situations --- on your lap, on your desk, in bed --- and you are often recalibrating the pen to accomodate the changed writing angle, there is a gesture for that too:


and an associated AppleScript as well:


tell application "System Preferences"

activate

reveal pane "Pen Tablet"

end tell


delay 0.5

try


tell application "System Events"

tell process "System Preferences"

-- get every UI element of window "Pen tablet"

-- get properties of every button of window "Pen Tablet"

-- get every UI element of every tab group of window "Pen Tablet"

tell radio button "Calibrate" of tab group 1 of window "Pen Tablet" to click

tell button "Calibrate…" of tab group 1 of window "Pen Tablet" to click


end tell

end tell


on error

tell application "System Events" to key code 76

delay 2.5

tell application "System Events"

tell process "System Preferences"

tell radio button "Calibrate" of tab group 1 of window "Pen Tablet (32-bit)" to click

tell button "Calibrate…" of tab group 1 of window "Pen Tablet (32-bit)" to click


end tell

end tell

end try


tell application "System Preferences"

quit

end tell


It is all magic.



Reply by EricN on November 23, 2009 at 9:32pm


I'm told that GUI scripting is difficult to do well since different systems with different setups may behave differently. It appears that I may have walked into that with one of the last AppleScripts. I have noticed that some Modbooks can open the "Pen Tablet" preference pane with the "Calibrate" window instead of the "Pen" window. To accommodate this possibility, the erasure toggle script needs to be modified to read:


tell application "System Preferences"

activate

reveal pane "Pen Tablet"

end tell


delay 0.7

try

tell application "System Events"

tell process "System Preferences"


tell radio button "Pen" of tab group 1 of window "Pen Tablet" to click


tell window "Pen Tablet" to tell tab group 1 to tell checkbox "Enable Eraser" to click


end tell

end tell


on error

tell application "System Events" to key code 76

delay 2.5

tell application "System Events"

tell process "System Preferences"


tell radio button "Pen" of tab group 1 of window "Pen Tablet (32-bit)" to click

tell window "Pen Tablet (32-bit)" to tell tab group 1 to tell checkbox "Enable Eraser" to click


end tell

end tell


end try


tell application "System Preferences"

quit

end tell


Reply by EricN on November 25, 2009 at 5:18pm


I find that the Quickclicks on-screen keyboard is always in the way --- right on top of scroll bar or icon that I want access to. So I always either hide or put it on the edge of the desktop where I can barely see it. Thus, when I need it, I have trouble finding it. It would really be great if whenever I need it, it would appear and flash so I could quickly find it. Well ... there is a gesture for that:


And an AppleScript to make it work:


set runningApps to "" as string

set frontmostApp to "" as string


tell application "System Events"

set runningApps to the name of every process whose background only is false

repeat with p in runningApps

if process p is frontmost then

set frontmostApp to p

exit repeat

end if

end repeat

end tell


tell application "Axiotron Quickclicks"

Show Keyboard

Hide Keyboard

Show Keyboard

delay 0.1

Hide Keyboard

Show Keyboard

delay 0.1

Hide Keyboard

Show Keyboard

end tell


tell application frontmostApp

activate

end tell


Happy Thanksgiving.


Quote    Reply   
Remove this ad
Remove this ad
avatar

ericn

superstar

Posts: 284

#1 [url]

May 5 10 5:24 PM

In response to Dylan's forum posting, I started thinking about better ways to get the virtual keyboard out of the way when I'm not using it. As a first step towards getting the virtual keyboard (Axiotron Quickclicks) to auto-hide, I built this AppleScript, which toggles the keyboard between two positions, one of which will be where I want it when I'm using it, and one will be where I want it when I want it out of the way:


[Note: To work properly as an Abracadabra gesture, this script must be saved as an application, an option in AppleScript Editor's SaveAs dialog. Alternatively, you may download the attached file: KeyboardToggle.zip, which contains the script as an app.]


property lastPosition : {1230, 100}


tell application "Axiotron Quickclicks"

Hide Keyboard

Show Keyboard

end tell


tell application "System Events"

tell process "Axiotron Quickclicks"


set theDifference to {0, 0}

set theRate to {0, 0}

set theStart to {0, 0}

set thePlace to {0, 0}

set thePosition to position of window 1

if lastPosition is thePosition then

set lastPosition to {1230, 150}

end if

set theSteps to 0

repeat with i from 1 to 2

set item i of theDifference to (item i of thePosition) - (item i of lastPosition)

if item i of theDifference > theSteps then set theSteps to item i of theDifference

if -(item i of theDifference) > theSteps then set theSteps to -(item i of theDifference)

end repeat

set theSteps to (theSteps / 180) as integer

if theSteps = 0 then set theSteps to 1

repeat with i from 1 to 2

set item i of theRate to ((item i of theDifference) / theSteps)

end repeat


repeat with i from 1 to 2

set item i of theStart to (item i of lastPosition) + theSteps * (item i of theRate)

end repeat

log {thePosition, lastPosition, theDifference, theRate, theStart, theSteps}

repeat with i from 0 to theSteps

set item 1 of thePlace to ((item 1 of theStart) - (item 1 of theRate) * i) as integer

set item 2 of thePlace to ((item 2 of theStart) - (item 2 of theRate) * i) as integer

set position of window 1 to thePlace

end repeat



end tell

end tell

tell application "System Events"

tell process "Axiotron Quickclicks"

set lastPosition to thePosition

end tell

end tell


Download: KeyboardToggle.zip


Click here to view the attachment

Quote    Reply   
avatar

ericn

superstar

Posts: 284

#2 [url]

May 7 10 9:20 PM

I've re-wrote the KeyboardToggle script using a little different approach, which lets it run a bit faster [download new zip-file at end of The post]:


property lastPosition : {1230, 100}


tell application "Axiotron Quickclicks"

Hide Keyboard

Show Keyboard

end tell


tell application "Axiotron Quickclicks"


set theDifference to {0, 0}

set theRate to {0, 0, 0, 0}

set theStart to {0, 0, 0, 0}

set thePlace to {0, 0, 0, 0}

set theBounds to bounds of window 4

set thePosition to {item 1 of theBounds, item 2 of theBounds}

set theSize to {(item 3 of theBounds) - (item 1 of theBounds), (item 4 of theBounds) - (item 2 of theBounds)}

if lastPosition is thePosition then

set lastPosition to {1230, 150}

end if


set theSteps to 0

repeat with i from 1 to 2

set item i of theDifference to (item i of thePosition) - (item i of lastPosition)

if item i of theDifference > theSteps then set theSteps to item i of theDifference

if -(item i of theDifference) > theSteps then set theSteps to -(item i of theDifference)

end repeat

set theSteps to (theSteps / 180) as integer

if theSteps = 0 then set theSteps to 1

repeat with i from 1 to 2

set item i of theRate to ((item i of theDifference) / theSteps)

set item (i + 2) of theRate to ((item i of theDifference) / theSteps)

end repeat


repeat with i from 1 to 2

set item i of theStart to (item i of lastPosition) + theSteps * (item i of theRate)

set item (i + 2) of theStart to (item i of theStart) + (item i of theSize)

end repeat

log {thePosition, lastPosition, theDifference, theRate, theStart, theSteps}

delay 0.15

repeat with i from 0 to theSteps


set item 1 of thePlace to ((item 1 of theStart) - (item 1 of theRate) * i) as integer

set item 2 of thePlace to ((item 2 of theStart) - (item 2 of theRate) * i) as integer

set item 3 of thePlace to ((item 3 of theStart) - (item 3 of theRate) * i) as integer

set item 4 of thePlace to ((item 4 of theStart) - (item 4 of theRate) * i) as integer


set bounds of window 4 to thePlace

end repeat


end tell


set lastPosition to thePosition



Download:  KeyboardToggle1.zip


Click here to view the attachment

Quote    Reply   
avatar

ericn

superstar

Posts: 284

#3 [url]

May 10 10 11:39 PM

Now that Axiotron Quickscript is finally out of beta, they have finally made it possible to insert text without following up with a space or some other character. So it is at last possible to use it with an incremental search box like Quicksilver.

In order to make things fast and easy, I've created an AppleScript (of course) to invoke both Quickscript and Quicksilver simultaneously, and then attached the script to an Abracadabra gesture:



Alternatively, the AppleScript could be associated with a keystroke by creating a Service Menu item. Quickscript excellent handwriting recognition combined with Quicksilver's speedy search make getting things done kind of fun.

The AppleScript:


tell application "Axiotron Quickscript" to quit


--------------- If you never use Apple's Ink Anywhere, ------------------

--------------- you can safely remove the script between the lines ----

---------------------------------------------------------------------------------

set WriteAnywhere to (do shell script "/usr/bin/defaults read com.apple.ink.framework recognitionEnabled")

--return WriteAnywhere

if WriteAnywhere is "1" then


tell application "System Preferences"

activate

reveal pane "Ink"

tell application "System Events"

tell process "System Preferences" to tell window "Ink" to tell checkbox "Allow me to Ink in any application" of group 1 of tab group 1 to click

end tell

quit

end tell

end if

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------


delay 0.02

tell application "Axiotron Quickscript" to activate


tell application "System Events"


-- Cancel Trial License dialog if it appears

tell process "Axiotron Quickscript"

get every window whose title is "Trial license"

if result is not {} then

key code 53

delay 0.01

end if

end tell


-- This section starts Quicksilver if not running ----------------

-- Needed only if script is run from outside Quicksilver -----

get every process whose name is "Quicksilver"

if result is {} then

tell application "Quicksilver" to activate

delay 1

end if

-------------------------------------------------------------------------


end tell


-- Invoke Quicksilver

tell application "System Events" to key code 49 using control down

delay 0.01

-- Clear Quicksilver's dialog box

tell application "System Events" to tell process "Quicksilver" to key code 51


tell application "Quicksilver" to activate



Download: Qsilver-Qscript.scpt.zip




For those who like to use Quicksilver's calculator or text processing, I've also got an AppleScript that invokes Quicksilver in text entry mode.


The gesture:




The AppleScript:



tell application "Axiotron Quickscript" to quit


--------------- If you never use Apple's Ink Anywhere, ------------------

--------------- you can safely remove the script between the lines ----

---------------------------------------------------------------------------------

set WriteAnywhere to (do shell script "/usr/bin/defaults read com.apple.ink.framework recognitionEnabled")

--return WriteAnywhere

if WriteAnywhere is "1" then


tell application "System Preferences"

activate

reveal pane "Ink"

tell application "System Events"

tell process "System Preferences" to tell window "Ink" to tell checkbox "Allow me to Ink in any application" of group 1 of tab group 1 to click

end tell

quit

end tell

end if

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------


delay 0.02

tell application "Axiotron Quickscript" to activate


tell application "System Events"


-- Cancel Trial License dialog if it appears

tell process "Axiotron Quickscript"

get every window whose title is "Trial license"

if result is not {} then

key code 53

delay 0.01

end if

end tell


-- This section starts Quicksilver if not running ----------------

-- Needed only if script is run from outside Quicksilver -----

get every process whose name is "Quicksilver"

if result is {} then

tell application "Quicksilver" to activate

delay 1

end if

-------------------------------------------------------------------------


end tell


-- Invoke Quicksilver

tell application "System Events" to key code 49 using control down

delay 0.05

-- Clear Quicksilver's dialog box

tell application "System Events" to tell process "Quicksilver" to key code 51

delay 0.05

-- Open Quicksilver's Text Mode

tell application "System Events" to tell process "Quicksilver" to keystroke "."


tell application "Quicksilver" to activate



Download: Qsilver-QscriptText.scpt.zip

Quote    Reply   
Add Reply

Quick Reply

bbcode help