Reading from files+Opening files...help?

Joined
Dec 30, 2005
Messages
22
Reaction score
0
Hey all. I have a program (Well, an idea actually) that would open a list of apps for me. I don't want to hard-code the apps in though, because I might want to change them later. So what I want is something like this:

FilesToOpen.txt (Linebreak delimited)
Macintosh HD:Applications:Adium.app
Macintosh HD:Applications:Stickies
Macintosh HD:Applications:Mail.app

How do I make this script iterate through this list and open each one without me having to change the script if I want to add a new program? Any ideas?

Thanks in advance,
Kman:D
 
Joined
Mar 28, 2006
Messages
198
Reaction score
5
What you could do is make a folder on your hard drive and put an alias to each program you want to launch with your script into the folder, so you can add or remove programs as needed, then do something like this:

tell application "Finder"
activate
open folder "Folder_with_aliases" of folder "Desktop" of folder "Your_User_name" of folder "Users" of startup disk
tell application "System Events"
tell process "finder"
keystroke "a" using command down
delay 1
keystroke "o" using command down
end tell
end tell
end tell

this opens that folder with the aliases in it, selects all and opens. the only thing hard coded into a script like this would be the name of the folder and it's location.

to get the keystroke commands to work you'll need to have the "Enable access for assistive devices" checkbox checked in Universal Access...
 
Joined
Dec 30, 2005
Messages
22
Reaction score
0
What you could do is make a folder on your hard drive and put an alias to each program you want to launch with your script into the folder, so you can add or remove programs as needed, then do something like this:

tell application "Finder"
activate
open folder "Folder_with_aliases" of folder "Desktop" of folder "Your_User_name" of folder "Users" of startup disk
tell application "System Events"
tell process "finder"
keystroke "a" using command down
delay 1
keystroke "o" using command down
end tell
end tell
end tell

this opens that folder with the aliases in it, selects all and opens. the only thing hard coded into a script like this would be the name of the folder and it's location.

to get the keystroke commands to work you'll need to have the "Enable access for assistive devices" checkbox checked in Universal Access...

First, let me say thank you. This is a huge help. Just a few more Q's:

1. Is it possible to delay before opening each one? Say, open one application, wait 30 seconds and open the next?

2. Is there a way to make it check to see if Assistive Devices is turn on, and throw an error if it's not?

Thanks again.
 
Joined
Mar 28, 2006
Messages
198
Reaction score
5
Number 2 is easy... provided you're running 10.3 or higher...

tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application "System Preferences"
activate
set current pane to ¬
pane "com.apple.preference.universalaccess"
set the dialog_message to "This script utilizes " & ¬
"the built-in Graphic User Interface Scripting " & ¬
"architecture of Mac OS X " & ¬
"which is currently disabled." & return & return & ¬
"You can activate GUI Scripting by selecting the " & ¬
"checkbox “Enable access for assistive devices” " & ¬
"in the Universal Access preference pane."
display dialog dialog_message buttons {"Cancel"} ¬
default button 1 with icon 1
end tell
end if


This script is straight off Apple's Applescript site, and it checks to see if assistive devices are enabled, and if they're not, opens Universal Access so you can check the checkbox...
 
Joined
Dec 30, 2005
Messages
22
Reaction score
0
Number 2 is easy... provided you're running 10.3 or higher...

tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application "System Preferences"
activate
set current pane to ¬
pane "com.apple.preference.universalaccess"
set the dialog_message to "This script utilizes " & ¬
"the built-in Graphic User Interface Scripting " & ¬
"architecture of Mac OS X " & ¬
"which is currently disabled." & return & return & ¬
"You can activate GUI Scripting by selecting the " & ¬
"checkbox “Enable access for assistive devices” " & ¬
"in the Universal Access preference pane."
display dialog dialog_message buttons {"Cancel"} ¬
default button 1 with icon 1
end tell
end if


This script is straight off Apple's Applescript site, and it checks to see if assistive devices are enabled, and if they're not, opens Universal Access so you can check the checkbox...
Great. I'll implemet this as soon as I've slept off my food-induced coma after Thanksgiving!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top