Re: Binary math operations (and, or, etc.)
Re: Binary math operations (and, or, etc.)
- Subject: Re: Binary math operations (and, or, etc.)
- From: Stephen Jonke <email@hidden>
- Date: Wed, 8 Jun 2005 16:32:52 -0400
I ended up using perl, which I know little about, via "do shell
script" to do this. For example:
do shell script "perl -e 'print " & windowKeyModifiers & " & 1048576'"
That returns "1048576" if the bit is set and "0" otherwise (yes, in
quotes!) I'll have to see if has' solution is faster, but this does
work. Here is my entire script for determining the spotlight hotkey
settings:
tell application "System Events"
if exists property list file
":~:Library:Preferences:com.apple.spotlight.plist" then
set spotlightProps to property list file
":~:Library:Preferences:com.apple.spotlight.plist"
set spotlightKeys to property list item "HotKeys" of
spotlightProps
set menuKeyEnabled to value of property list item
"MenuVirtualKeyEnabled" of spotlightKeys
set menuKey to value of property list item "MenuVirtualKey"
of spotlightKeys as integer
set menuKeyModifiers to value of property list item
"MenuVirtualKeyModifier" of spotlightKeys as integer
set windowKeyEnabled to value of property list item
"WindowVirtualKeyEnabled" of spotlightKeys
set windowKey to value of property list item
"WindowVirtualKey" of spotlightKeys as integer
set windowKeyModifiers to value of property list item
"WindowVirtualKeyModifier" of spotlightKeys as integer
set menuKeyMods to {}
if (do shell script "perl -e 'print " & menuKeyModifiers &
" & 1048576'") ≠ "0" then set menuKeyMods to menuKeyMods & command
down
if (do shell script "perl -e 'print " & menuKeyModifiers &
" & 524288'") ≠ "0" then set menuKeyMods to menuKeyMods & option down
if (do shell script "perl -e 'print " & menuKeyModifiers &
" & 262144'") ≠ "0" then set menuKeyMods to menuKeyMods & control down
if (do shell script "perl -e 'print " & menuKeyModifiers &
" & 131072'") ≠ "0" then set menuKeyMods to menuKeyMods & shift down
set windowKeyMods to {}
if (do shell script "perl -e 'print " & windowKeyModifiers
& " & 1048576'") ≠ "0" then set windowKeyMods to windowKeyMods &
command down
if (do shell script "perl -e 'print " & windowKeyModifiers
& " & 524288'") ≠ "0" then set windowKeyMods to windowKeyMods &
option down
if (do shell script "perl -e 'print " & windowKeyModifiers
& " & 262144'") ≠ "0" then set windowKeyMods to windowKeyMods &
control down
if (do shell script "perl -e 'print " & windowKeyModifiers
& " & 131072'") ≠ "0" then set windowKeyMods to windowKeyMods &
shift down
return {menuKeys:{isEnabled:menuKeyEnabled,
keyCode:menuKey, modKeys:menuKeyMods}, windowKeys:
{isEnabled:windowKeyEnabled, keyCode:windowKey,
modKeys:windowKeyMods}}
else
return missing value
end if
end tell
Suggestions for improvement certainly accepted!
Steve
_________________________________________________________________
Stephen Jonke email@hidden
On Jun 8, 2005, at 3:12 PM, deivy petrescu wrote:
On Jun 8, 2005, at 11:01, Stephen Jonke wrote:
When I try either of these scripts, the following inputs produce
the "No can do!" dialog:
andorxorit(3670288, 1048576) -> toand should be 1048576
andorxorit(3010440, 1048576) -> toand should be 0
What I'm trying to do is see if a certain bit or bits is set.
Steve
Steve, you have to convert 3670288 to binary base before performing
binary operations.
Look for my matematica libraries here <http://www.dicas.com/MacOs/
script_download.html>
The modulus you want is 1. It converts numbers from bases 2 through
16 to 10 and vice versa.
So you will need three scripts.
And by what I see you are doing, use Nigel's version, it will work
for you, whereas mine will not.
deivy petrescu
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden