do shell script problem

I’ve a fpc/lazarus/intel application running on Mac OS X 10.5.6. This application is launched from AppleScript application.

When I’m running fpc application from the terminal (or from applescript in this way

do shell script "open PathToMyApp"

) - it runs well. But when I’m running it from a AppleScript script like this

do shell script PathToMyApp

it can’t read/write unicode inifile - it shows only “?” when special characters are present. As another site said (http://forum.soft32.com/mac/Recipes-shell-script-commands-applescript-ftopict38741.html_-

So I’ve tried following

do shell script "/bin/tcsh -c PathToMyAppWithQuotes"

But same problem appears. I understand that it could be bug of fpc library, but it works well when running from Terminal on Leopard/Tiger with any system language (I’ve tried to change system language at Preferences->International) - so I’m thinking of solving problem within AppleScript.
This way -

do shell script "open PathToMyApp"

is not solution for me because it leaves Terminal window opened.

Anybody had similar problem?

Model: MacBook Pro
Operating System: Mac OS X (10.5)

Have you tried creating a ‘tcsh’ file and calling that from AppleScript.
I have had more success doing it this way.

Craig, thanks for prompt reply!

Do you mean this way?

do shell script "/bin/tcsh -c PathToMyAppWithQuotes"

Yes, I have. But no luck.

No. I mean create an external ‘tsch’ file and call that from AS.

I would do it in Ruby like this.


#!/usr/bin/env ruby -w

puts "I will do some work for you and return the results!"

And then call it from AS like this.


set theResult to do shell script "ruby /path/to/file.rb"

--or if you make it executable
set theResult to do shell script "./path/to/file "  

Does that make sense?

Thank you! I’ll try this now.
As I’ve just found here may be the source of problem - locale:

As I googled - I can’t change locale for “do shell script” to be the same as in Terminal?
Am I right?

Hi Alex,

I just read the entire post again and I must apologize for my
previous responses. You were already doing it that way. I did
not get much sleep last night is my only excuse.

I could not find anything on changing the locale either. You
say it works fine using the open command but that leaves the
Terminal window open. Would it be sufficient to simply close
the window once the command has run?

Or could you use something like ‘&> /dev/null &’ and close
the window immediately?

Craig

Craig, thank you for you help!

Yes, but as I understand I can’t close terminal window without modifying user preferences.

Could you show me some example because I don’t understand how to use /dev/null.

Alex

Here is a good article on /dev/null
[url=http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/]http://www.xaprb.com/blog/2006/06/06/what-does-devnull-21-mean/[/url]

This is what I was thinking.


tell application "Terminal"
	activate
	do script "COMMAND_TO_PERFORM > /dev/null/2>&1"
	tell front window to close
end tell

Thank you again for help!

Unfortunately it opens 1 terminal window after the activate command. So following code worked for me with small note - I have to specify time for running command:


tell application "Terminal"
	do script command
	delay 4
	tell front window to close
end tell

and Terminal remains open (but without any windows).

I do not want to use the “quit” command because it could cause problem in case when there are opened processes in Terminal.

So it seems I’ve draft solution. But to ensure terminal window is not shown I will look for any methods of specifying locale, especially because in Mac OS 10.4.* as I know the default locale is “C” but not “*.UTF8”.

Thanks!

You could check to see if Terminal is active before you run your command and only close after your command if it was not previously open. If they already have it open you would not want to close it anyway wether a process was running or not.

Thank you again!

p.s. (Offtopic) Unfortunately I can just say thanks. (In my native country I/my friends used to give beer to colleague who helped a lot, so if you will attend wwdc’09 you will have a person to drink beer with :wink: )

Sounds good! :smiley: