That's really cool. Thanks for this.
Here are two suggestions to make it easier for users who aren't tech
savvy:
1. Because Applescripts remember changes to their property values
between executions, it is possible to query the user for necessary
information the first time the script is run. It will only be
necessary for the user to enter it once, and the data will be saved
forever, unless the script is opened and recompiled.
This means that the script author can do this:
property usrnm : null
property psswrd : null
property phnm : null
if usrnm is null then set usrnm to (display dialog "Please enter your
full Gmail address. You should only have to do this the first time you
run this script." default answer "")
if psswrd is null then set psswrd to (display dialog "Please enter
your Google Voice password. You should only have to do this the first
time you run this script." default answer "")
if phnm is null then set phnm to (display dialog "Please enter your
Google Voice phone number. You should only have to do this the first
time you run this script." default answer "")
As an added benefit, this method of getting the user's password is
much less insecure, because it would require the greatest care on the
part of any attacker to extract the password from the saved properties
of the script without disturbing and thereby obliterating it. Of
course, for true security, this information should be stored and
retrieved in the keychain and retrieved using keychain scripting.
2. Instead of saving a separate php script file and then executing it
using
do shell script "php -f " & shFile & " " & thedigits & " " & usrnm & "
" & " " & psswrd & " " & phnm
you can simply include the full text of the php code in the
Applescript itself, and execute it using
do shell script "php -r '<your php code here>'"
This would save the user from having to manage a separate file. They
could simply drop the Applescript into QS's Actions folder and be done
with installation.
To do this will require adding proper escaping to your php code.
First, Applescript will require you to escape all double quotes ( " →
\" ). Second, because php -r requires single quotes around the entire
argument code block, you will have to escape all the single quotes;
moreover, to prevent Applescript from trying to interpret those escape
sequences, you have to double escape the single quotes ( ' → \\' ). Of
course, this is a simple find and replace operation in your text
editor, so no big deal.
3. Instead of passing in further arguments and then mucking around
with $argv[n] in your php code, you can simply substitute your
Applescript variables directly into the code block. For example, you
can delete
$usrnm = $argv[2];
$psswrd = $argv[3];
$phone = $argv[4];
from the first part of your php code, and replace
$gv = new GoogleVoice(\"$usrnm\", \"$psswrd\");
with
$gv = new GoogleVoice(\"" & usrnm & "\", \"" & psswrd & "\");
(As can be seen, these examples already display the necessary escaping
of double quotes.) In the second instance, we are simply substituting
your existing Applescript variables directly into the php code, rather
than making the php binary parse and interpret them. Now, with this
script the user won't know the difference, but for future
Applescripting that you do, it can come in handy as a time saver and
performance enhancer.
I hope these suggestions are helpful to you. If you could implement
the first two suggestions in order to make it easy for average users
to install, I would really like to add this script to the Applescripts
for Quicksilver page here on the group. Again, thanks for this helpful
script!