Compare Boolean "OR" function

Compare Boolean "OR" function

Postby JSapp » Tue Jan 18, 2011 10:49 am

I needed a way to read the contents of my Clipboard and perform a set of commands based upon those contents. This is simple enough really, as you just use a "Compare Variable" step in QuicKeys with the settings "Clipboard" "Equals", enter in your variable, and write further steps for the commands to run if that value is found.

My issue is, I have multiple choices (say, if the Clipboard contained "T20" or "A34") that would lead to one set of instructions (say, set "A") and other values from the Clipboard that should lead to a different set of instructions. In total I have about 60 expected values from the Clipboard that will in turn run about 25 different sets of instructions, but I can't seem to find a way to perform a Boolean "OR" function so I can have a number of different values be read by a single "Compare Variable" step and thus lead to a set of instructions that is identical for all of those given values.

As of right now, I have a shortcut that compares the Clipboard to each individual value one at a time and if that step fails it checks the next value. But this Comparator I wrote is 143 steps long, with each set of instructions another 20 steps, and if I were able to group a set of values I could easily have cut the time and steps it took to accomplish this in half.

So what I'm asking for is a Boolean "OR" function (and perhaps other Boolean logic functions such as "AND"?) when using the "Compare Variable" step, or any variable step that allows you to enter in the expected value. If this is already possible and I missed how to do this when I read the manual and searched the forums, please let me know! I'd very much appreciate it.
JSapp
 
Posts: 6
Joined: Wed Jan 12, 2011 9:45 am

Re: Compare Boolean "OR" function

Postby gb2 » Tue Jan 18, 2011 2:13 pm

You could create a QuicKeys Equation function to do it:

1) select Variables and Functions Editor from the Window menu
2) click on the plus sign at the bottom of the window and select New Equation Function
3) it will ask you to name the function - so give it something like Values
4) it will then create a blank function - search for the following lines:

the default function_paramcount from this:
Code: Select all
on function_paramcount()
return 0
end function_paramcount

to this:
Code: Select all
on function_paramcount()
return 1
end function_paramcount


the default function_calculate from this:
Code: Select all
on function_calculate()
-- Do some amazing things here and return a value
end function_calculate

to this:
Code: Select all
on function_calculate(theList)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set aList to every text item in theList
set AppleScript's text item delimiters to tid
if aList contains (the clipboard) then
return the clipboard
else
return ""
end if
end function_calculate

5) click the Compile button and if no errors then click Save.
6) now you can go into one of your Compare steps and remove the value you have there and replace it with the new function called Values by selecting Values from the Add Equation Item pop-up under Functions.
7) it will add the red Values lozenge with the insertion point flashing within it. Type in your T20 A34 and whatever other values you want this compare to test. You would just type them in with only a Space between the values.
User avatar
gb2
Site Admin
 
Posts: 2868
Joined: Mon Feb 06, 2006 5:22 pm

Re: Compare Boolean "OR" function

Postby JSapp » Tue Jan 18, 2011 4:56 pm

Thanks, I don't have time to work on this right now but I'll definitely give this a shot this week, and post my results.
JSapp
 
Posts: 6
Joined: Wed Jan 12, 2011 9:45 am

Re: Compare Boolean "OR" function

Postby JSapp » Wed Jan 19, 2011 10:54 am

Excellent instructions, this worked the first time. Thank you!

Suggestion (after all, this IS the Feature Requests forum)- since this function script is actually useable as a Boolean "OR" for any number of values in virtually any format that can be typed, could it be integrated into QuicKeys on the "Compare Variable" step under the Add Equation Item drop-down as a permanent option?

Whether or not the permanent "OR" makes the cut, I'll definitely be saving this script for my own use in the future. Thanks again.
JSapp
 
Posts: 6
Joined: Wed Jan 12, 2011 9:45 am


Return to QKM Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron