Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 02-26-2010, 02:36 PM   #1
magikseb
Prospect
 
Join Date: Feb 2010
Posts: 10
Question Start AppleScript app holding alt to start in special mode

Is there a way to build into my applescript app a feature, where if I started it up whilst holding say.. alt it would start in a special mode of some sort (which I could define) ? How would I code it?
magikseb is offline   Reply With Quote
Old 02-27-2010, 03:00 PM   #2
renaultssoftware
MVP
 
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
I've looked it up, and thing is NO. Unless you launch the script from within another that detects if Option is down… Just a thought.
__________________
Get Icon Creator and support me.
renaultssoftware is offline   Reply With Quote
Old 02-27-2010, 05:36 PM   #3
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
I coulda sworn there a way to have system events detect stuff like 'option key down' already built-in to AppleScript... but i can't seem to find it.

Found this though: Customizing Application startup Behavior [Key down on launch]

[still looking]

Last edited by Hal Itosis; 02-27-2010 at 05:54 PM.
Hal Itosis is offline   Reply With Quote
Old 02-27-2010, 05:54 PM   #4
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,141
You're probably thinking of the keystroke and/or keycode command enumeration:

keystroke unicode text using some modifier
__________________
17" MBP, OS X; 27" iMac, both OS X 10.9.x (latest)
NovaScotian is online now   Reply With Quote
Old 02-27-2010, 06:00 PM   #5
Hal Itosis
Hall of Famer
 
Join Date: Apr 2002
Posts: 3,315
Not that no... i seem to remember i had an OS9 script that did this (maybe with the help of some osax?). Anyway, that feels like ages ago now, and i can't seem to find anything like it. [some of my OS9 scripts won't even open in Script Editor anymore, a few claiming to be read-only (which i almost never did).]
Hal Itosis is offline   Reply With Quote
Old 02-27-2010, 08:38 PM   #6
Red_Menace
All Star
 
Join Date: Mar 2006
Location: Littleton, Colorado, USA
Posts: 515
There was another thread at macscripter where a command line utility to get modifier keys was posted - http://macscripter.net/viewtopic.php?id=29456

From there, you would just have to look to see which modifier keys are pressed at launch and adjust the script accordingly.
__________________
MacBook Pro / OS X Mavericks (10.9.3) / Xcode 5.1.1 / RubyMotion FTW
Red_Menace is offline   Reply With Quote
Old 02-28-2010, 08:48 AM   #7
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,141
I remember that from last summer -- StefanK is a frequent contributor (and I'm an Admin under another name). I saved it at the time, but didn't use it. Now, I can't remember how to. What do I do with the code to save it as an executable?
__________________
17" MBP, OS X; 27" iMac, both OS X 10.9.x (latest)
NovaScotian is online now   Reply With Quote
Old 02-28-2010, 09:57 AM   #8
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
Quote:
Originally Posted by NovaScotian
I remember that from last summer -- StefanK is a frequent contributor (and I'm an Admin under another name). I saved it at the time, but didn't use it. Now, I can't remember how to. What do I do with the code to save it as an executable?

That is a very neat and handy command line tool.

Just download the zip. Unpack it.
In the do shell script "/path/to/checkModifierKeys shift option" example, change the /path/to/checkModifierKeys to the path to the unpacked file.

When you run the do shell. If you are holding down shift + option.
The result will be a 1
If not the result will be a 0

Use the result as your true or false.
__________________
MH.
mark hunte is offline   Reply With Quote
Old 02-28-2010, 10:37 AM   #9
NovaScotian
League Commissioner
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 5,141
Quote:
Originally Posted by mark hunte
That is a very neat and handy command line tool.

Just download the zip. Unpack it.
In the do shell script "/path/to/checkModifierKeys shift option" example, change the /path/to/checkModifierKeys to the path to the unpacked file.

When you run the do shell. If you are holding down shift + option.
The result will be a 1
If not the result will be a 0

Use the result as your true or false.

Useful indeed, Mark. Didn't see the link in the thread for the download. Great stuff, thanks.

I suppose you could put this in the resources of a bundle as well with the first line of the script referring to it.
__________________
17" MBP, OS X; 27" iMac, both OS X 10.9.x (latest)

Last edited by NovaScotian; 02-28-2010 at 11:00 AM.
NovaScotian is online now   Reply With Quote
Old 02-28-2010, 12:14 PM   #10
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
Quote:
Originally Posted by NovaScotian
I suppose you could put this in the resources of a bundle as well with the first line of the script referring to it.

Yes you can, good idea, you can use something like:

Code:
set path_to_resource to POSIX path of (path to resource "checkModifierKeys")
do shell script quoted form of path_to_resource & " shift option"
save the Script as a 'Script bundle' or a 'Application'

Then add the file.
and save again.
__________________
MH.
mark hunte is offline   Reply With Quote
Old 03-04-2010, 01:34 PM   #11
magikseb
Prospect
 
Join Date: Feb 2010
Posts: 10
Thumbs up

Wow, thanks for that guys,
magikseb is offline   Reply With Quote
Reply

Tags
app, applescript, mode, special

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 06:54 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.