Ex Windows IT Tech

Joined
May 28, 2007
Messages
3
Reaction score
0
I have finally made the switch. I am constantly hacking around on the registries and in DOS on pc's. I am now a dedicated Macbook pro owner. I need to write an applescript to open a program that has to be initialized through Terminal.

I have the following

tell application "Finder"
activate
select window of desktop
select window of desktop
open application file "Terminal.app" of folder "Utilities" of folder "Applications" of startup disk
This is where I get stuck....I had cd "/users/username/"
Then run "./filename.sh"
end tell


Any help is greatly appreciated. Whether it be a mock script, or access to a resource to writing scripts and all the commands usable in Applescript editing.
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Hi there and welcome !

try it this way...

Code:
do shell script "/Users/[B]yourusername[/B]/Desktop/hello.sh"

Then using your editor of choice...

Code:
#!/bin/sh

osascript -e 'say "[hello from Ric]" using "Zarvox"'


You can use "do shell script" to execute commands ...this is done without opening terminal...

I have attached the test files below...

Make sure you set the correct permissions for the Shell Script to run...

Code:
 chmod u+x /Users/[B]yourusername[/B]/Desktop/hello.sh

regards

Ric
 

Attachments

  • hello.sh.zip
    223 bytes · Views: 332
  • test_Applescript.zip
    892 bytes · Views: 328

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Hi there,

here's a bit more for you...

Code:
tell application "Terminal"
	activate
	
	--the commands go here
	do script "pwd" in window 1
	delay 2
	do script "clear" in window 1
	delay 2
	do script "ls" in window 1
	
end tell

I have attached the script below...

regards

Ric
 

Attachments

  • Applescript for terminal.zip
    1.6 KB · Views: 322
Joined
May 28, 2007
Messages
3
Reaction score
0
Okay. I appreciate your feedback. I get this when I run the following script.

do shell script "/Users/Jeremy/iDine/tinapos.sh"

Exception in thread "main" java.lang.NoClassDefFoundError: net/jmonroe/tpv/forms/JFrmTPV

Any ideas?
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Hi there,

'do shell script' will run the 'commands' without opening terminal, depending on what is in your file...tinapos.sh does it need the terminal to open ...for you to interact with it ?

If it does then you will need to use...

Code:
tell application "terminal"
--maybe add in a delay
delay 2
do script "/Users/Jeremy/iDine/tinapos.sh"
end tell

Does tinapos.sh run okay from the terminal directly ?

regards

Ric
 
Joined
May 28, 2007
Messages
3
Reaction score
0
Okay. Thanks again Ric. I entered those lines in to Applescript, however, I get an error. And by the way, if you manually start Terminal and then cd to the directory...and type the .sh command, it works beautifully. Here is the error that I get with the code you gave me....

Exception in thread "main" java.lang.NoClassDefFoundError: net/idine/tpv/forms/JFrmTPV

I get a terminal window that opens, then another terminal window opened titled bash that enters the directory and command...and then that error is displayed in the second terminal window.

Any other suggestions?

Thanks.
 

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