Note: If you enjoy this article, you might also check out the Geeky Stuff section.
I'm so tickled I can't stand it. All right, so Speech Recognition stuff on a Mac is pretty darn cool by itself, but now I've got a nice Apple Script that opens up Safari with various tabs of my favorite sites, and it does this when I tell my Macbook "Get on it." Here's how I did it:
- Under System Preferences > Speech > Speech Recognition, make sure "Speakable Items" is set to "On." By default, to issue a voice command, you'll have to hold down the Esc key while you talk. I changed mine to the back tick because I use Esc in other applications to do other things; it's whatever works for you. If you want to change this, change the "Listening Key".
- Open Applications > AppleScript > Script Editor and enter the following code:
property links :
{"http://mail.google.com/mail/",
"http://www.3till7.net/wp-admin/",
"http://dubious.nu/forum/index.php?action=unread",
"http://icanhascheezburger.com/"}
tell application "Safari"
activate
set currWindow to front window
repeat with link in links
make new tab at the end of tabs in currWindow with properties {URL:link}
end repeat
end tell
Thanks to Takashi Yoshida for the basis of this script. Feel free to change the links shown to whatever you want Safari to open up with. I imagine this script could also be customized for Firefox, Opera, or whatever other browser you use, but that might take some fiddling around.
- Hit the Compile button in Script Editor and make sure the code gets syntax highlighted nicely, with no warnings displayed. Go ahead and save this script wherever you would like, but give it a name like "Get on it" or something like that. Not "get_on_it", but using spaces and everything.
- Copy your snazzy new script to Library > Speech > Speakable Items. If you're copying the script with Finder, that is your local Library, so the one inside your home folder.
- Hold down Esc (or whatever you set your Listening Key to be) and say, clearly, "Get on it". If all goes well, Safari should pop open with your links opened in separate tabs, with a blank tab showing. If you already have Safari open, this will just open up those links in new tabs, leaving your current tabs alone.
Pronunciation Issues
Being a southern girl by the grace of God and all that jazz, I have a bit of an accent. For me, my Apple Script works better if I name it "Getawnit", which looks more akin to how I sound so that the voice recognizer does a better job of understanding me. You want how the Mac says it to match how you're saying it. One way to test this is to have the Mac say the written version of what you want to say as your command:
- Under System Preferences > Speech > Text to Speech, check "Speak selected text when the key is pressed". Then choose "Set Key..." to choose which key combination you want to hit to make the Mac read selected text. Just hit the desired combination while the little window is open. I have Option+S set for mine.
- Open Applications > TextEdit. Type in how you think you sound when you're saying the desired command. For example, I made a script that will activate when I say "I'm bored," but for me, my words run together and I speak quickly, so "Mbord" is the name I chose for my script.
- Select the text you just typed and hit the key combination you entered in System Preferences (like Option+S). Does the Mac's voice match how you plan to speak the command? If so, then you have a good file name for your script.
Technical note: you'll need a microphone for this to work, obviously. I'm using a Macbook with a built-in microphone and I'm running OS X Leopard.
- Time:
- 7:21 PM
- Categories:
- OS X
- Tags:
- OS X, programming
- Comments:
-
3 comments / Add a comment »
Note: If you enjoy this article, you might also check out the Geeky Stuff section.
I installed Delicious Library earlier and have spent all afternoon and evening scanning in barcodes from my CD’s, DVD’s, books, and games. Wow, that sounds like the dorkiest thing ever: while everyone else in this country is watching the Superbowl, I’m sitting alone in my apartment, waving barcodes at my computer. I feel I have to redeem myself now… Um, I have lots of dates! I go to movies with my friends! I take a yoga class! Yeah…
Anyway, it’s really neat because it uses my Macbook’s iSight camera to scan in barcodes, then it grabs information about the product from Amazon. Now I can browse through all my media without leaving my laptop, and what’s nice is that I can sort things by Amazon users’ rating, genre, number of pages, etc. See this snazzy screenshot of my library:
This totally sounds like a paid post, but I promise it’s not, heh. The scanner worked reasonably well, but sometimes I had to search by title, author, or UPC. I think Amazon is a bit crazy with the ISBN’s, too, probably because of the ISBN number change that happened a while back: sometimes I would scan one thing and get something completely different in my library. I especially had trouble with Orson Scott Card and Stephen King novels, which sucked because I have so much of their stuff.
- Time:
- 8:29 PM
- Categories:
- Techy
- Tags:
- OS X
- Comments:
-
1 comment / Add a comment »
- Music:
- New and Approved (remix) by No Doubt
Note: If you enjoy this article, you might also check out the Geeky Stuff section.
Recently, I switched from a Powerbook to a Macbook, and to copy my files from one to the other, I used a pen drive. Since my pen drive has a FAT file system, it treats everything as being executable. This, however, is not the case on a UNIX-like file system like OS X. In order to save myself the hassle of manually chmodding thousands of files, I wrote this Ruby script:
#!/usr/bin/env ruby
require 'find'
require 'fileutils'
# Append to/remove from this list as necessary
Plain = ['php', 'txt', 'jpg', 'jpeg', 'gif', 'png', 'html', 'pdf', 'css', 'mp3', 'zip', 'tar.gz', 'tar', 'htm', 'psd', 'ai', 'ptg', 'cgi.pl', 'sphp', 'svn-base', 'default'].collect do |ext|
".#{ext}"
end.freeze
# Append to/remove from this list as necessary
Executable = ['pl', 'rb', 'cgi', 'sh'].collect do |ext|
".#{ext}"
end.freeze
$num_chmodded = 0
def chmod_and_puts( cmd )
puts cmd
system cmd
$num_chmodded += 1
end
def chmodder( start_dir )
num_skipped = 0
num_plain = 0
num_executable = 0
Find.find( start_dir ) do |path|
unless File.symlink?( path )
if FileTest.file? path
if is_plain? path
chmod_and_puts "chmod 644 \"#{path}\""
num_plain += 1
elsif is_executable? path
chmod_and_puts "chmod 755 \"#{path}\""
num_executable += 1
else
num_skipped += 1
end
elsif File.directory? path
chmod_and_puts "chmod 755 \"#{path}\""
num_executable += 1
else
num_skipped += 1
end
else
num_skipped += 1
end
end
puts "----------------------------------------------"
puts "Chmodded #{$num_chmodded} total:"
puts "\tExecutable: #{num_executable}"
puts "\tPlain: #{num_plain}"
puts "Skipped #{num_skipped} files/directories/symlinks"
end
def get_extension( path )
File.extname( path ).downcase
end
def is_executable?( path )
extension = get_extension( path )
if Executable.include? extension
true
else
false
end
end
def is_plain?( path )
extension = get_extension( path )
if Plain.include? extension
true
else
false
end
end
chmodder( '.' )
This goes through all the files and directories within the directory from which you run the script and chmods non-executable files to 644 (read+write on User, read on Group and Other) and executable files to 755 (read+write+execute on User, read+execute on Group and Other). If you're unfamiliar with the chmod command, you might want to read my beginning Linux guide.
- Time:
- 4:52 PM
- Categories:
- Linux, OS X, Ruby
- Tags:
- Linux, OS X, programming
- Comments:
-
0 comments / Add a comment »