Mac Help Forums


Reply
Thread Tools Display Modes

Reading from files+Opening files...help?

 
Member
kmancat's Avatar
Join Date: Dec 2005
Posts: 22
 
      21st November 2006
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
 
Reply With Quote
 
 
 
 
Senior Member
zeyhra's Avatar
Join Date: Mar 2006
Location: Santa Cruz, California
Posts: 198
 
      21st November 2006
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...
 
Reply With Quote
 
Member
kmancat's Avatar
Join Date: Dec 2005
Posts: 22
 
      21st November 2006
Quote:
Originally Posted by zeyhra View Post
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.
 
Reply With Quote
 
Senior Member
zeyhra's Avatar
Join Date: Mar 2006
Location: Santa Cruz, California
Posts: 198
 
      22nd November 2006
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...
 
Reply With Quote
 
Member
kmancat's Avatar
Join Date: Dec 2005
Posts: 22
 
      23rd November 2006
Quote:
Originally Posted by zeyhra View Post
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading dll files on a MAc Mel Comisarow Mac 33 2nd July 2010 03:48 AM
Reading ProDOS files with a Mac msean1941@gmail.com Misc 4 25th June 2005 08:16 PM
Reading song info from m4a (aac) files and mp3 files Ivo Boehme Programmer Misc 0 24th July 2004 05:24 PM
Reading word files on X Luke Siemaszko UK Macs 21 15th July 2004 07:48 AM
Reading pc files from Mac eric Misc 2 3rd April 2004 10:15 AM


All times are GMT +1. The time now is 05:00 AM.
Mac-Help.com is an independent website and is not affiliated with Apple Inc.


Welcome!
Welcome to the Mac Help Forums
 


Latest Threads
Help! Stupid computer is automatically logging me out
Elizaboo (6 Hours Ago, 10:41 PM)

URGENT Help. Crazy talk Mac!
Joeker (7 Hours Ago, 09:42 PM)

PDF Document
yura (16 Hours Ago, 12:13 PM)

Difficulties with internet speed (nothing to do with connection)
sammethh (22 Hours Ago, 06:36 AM)

Deleting a homepage/website form my mac book pro
rgandajg (1 Day Ago, 10:30 PM)

 


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51