Q&A: MacFixIt Answers

Readers ask questions about how to automate keystroke sequences in OS X, and other topics.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
4 min read

MacFixIt Answers is a feature in which I answer Mac-related questions e-mailed in by our readers.

This week, readers wrote in with questions on the possibility of false positive results from Apple's Hardware Test suite, how to locate lost files in iTunes libraries, and how to script a Mac to enter repeated keyboard button presses. I welcome views from readers, so if you have any suggestions or alternative approaches to these problems, please post them in the comments!

Question: False positives with Apple's Hardware Test suite
MacFixIt reader Javier asks:

Is it possible to get errors on these HW tests? I am getting a logic board error, but I have the feeling it is not the logic board that is wrong with my Mac Mini...

The hardware tests as mentioned in this article may detect a number of problems, which can be on the logic board or another component of the system.

Many of the tests performed just check the status of various sensors in the system, so while an error likely indicates a problem with the hardware, if a sensor itself is faulty it could indeed give a false positive result. Unfortunately, there's no easy way to check this.

Even in cases where a system appears to be running well, if the Apple Hardware Test is showing a problem, be sure to maintain a full and restorable backup of your computer (Apple's Time Machine should work great for this) in case a problem becomes evident.

Question: Inability to locate downloaded music from iTunes
MacFixIt reader Vince asks:

I have a program called TuneUp which is supposed to clean up songs, remove duplicates and other things. I also have a number of old iTunes Libraries. While purchases show up in my collection, when I go to play them they're missing. What's really weird is that I can find them in the downloaded page and play them from there. I'm starting to freak out because I basically don't know what's going on.

Try going to the Advanced section of the iTunes preferences and see what the path is for "iTunes Media folder location." This should be the place where iTunes is storing your downloaded music, and may not be a standard default location. Go to this folder in the Finder to see if you can locate the files in there. You can also try locating the files by searching for them with Spotlight, and if they show up then hold the Command key when you click to open them in the Spotlight search, and the system should reveal them in a Finder window for you. This will help you determine where the songs are.

Question: Automating keystroke sequences in OS X
MacFixIt reader Brian asks:

I'm trying to figure out how I can record and repeat key strokes. Most recently I have needed to repeat the following 2,800 times for a data entry project: "Right arrow, delete, delete, left arrow, left arrow, left arrow, left arrow, delete, (enter single digit), down arrow ... repeat"

I would do this in batches of 100 where the single digit would be the same and would love to create a simple, modifiable script. I have tried Automator, Terminal, and a few third-party apps but wasn't able to get it to work.

You might find the best option is to use AppleScript, which supports the commands "key code" and "keystroke" to invoke keyboard button presses. The key code option uses the AppleScript key code assignments (you can see them listed here) and the keystroke option uses the key's character.

To implement this, open the AppleScript Editor utility (in the Applications/Utilities folder) and use the following to sequence the key presses and have them be repeated:

tell application "Finder" to activate
repeat 2 times
     tell application "System Events" to key code 124
     tell application "System Events" to key code 51
     tell application "System Events" to key code 51
     tell application "System Events" to key code 123
     tell application "System Events" to key code 123
     tell application "System Events" to key code 123
     tell application "System Events" to key code 123
     tell application "System Events" to key code 51
     tell application "System Events" to keystroke "a" using shift down
     tell application "System Events" to key code 125
end repeat

Note that this is a relatively crude approach and I'm sure there are other more efficient and thorough approaches, but it should work. You can refine it to target a specific document or otherwise run some checks to make sure the key presses are done in the desired application.

The above script will activate the Finder and then run the key press sequence two times in the Finder. For the "digit" it enters the letter "a" as uppercase (with the Shift key down -- this modifier option can be changed to whatever you would like, or be removed).

The script can be saved as a script file that opens and runs in the editor, or as an application that can be run independently and launched as part of another script (such as a shell script). You can also implement this in Automator by using the Run AppleScript action.

Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.