0

I am new to applescripts and i want to automate a little bit of my app.So here is the thing

1) I am using textwrangler as an editor

2) After writing code and saving it i want to compile the file by opening terminal from applescript.I already installed llvm compiler.

3) As textwrangler provides me the a menu in meubar to open script editor so after opening it i am using "tell application "Terminal" to activate" it opens terminal

4) i want " gcc myfilename.c " to be passed as argument from applescript so that as soon terminal opens this string should be passed as argument and executable is generated

Can i Do that through scripts? Please help.

Ankur Singh
  • 25
  • 1
  • 4
  • 2
    possible duplicate of [Sending commands and strings to Terminal.app with Applescript](http://stackoverflow.com/questions/1870270/sending-commands-and-strings-to-terminal-app-with-applescript) – Digital Trauma Jul 30 '13 at 18:42

1 Answers1

0

Give this a try:

tell application "Terminal" to do script "gcc myfilename.c"

Running this without the Activate line you mentioned will still open Terminal if it isn't already open, but it won't bring it to the front. For that, Just turn the whole thing into a tell block and put the Activate back in there so it becomes:

tell application "Terminal"
    activate
    do script "gcc myfilename.c"
end tell
scohe001
  • 15,110
  • 2
  • 31
  • 51
  • Thanks for the script.it is very helpfull but as i already said that i want to automate things.As i have already wrote that a c file is opened in textwrangler or in any editor so i want the current file name to be passed to terminal like `gcc current_file_name.c` should be passsed also to terminal – Ankur Singh Jul 31 '13 at 14:47
  • 1
    @AnkurSingh Throw this line up above the terminal tell block `tell application "TextWrangler" to set filePath to ((characters 8 thru -1 of (URL of document 1 as string)) as string)` and then change `do script "gcc myfilename.c"` to `do script "gcc "&filePath` – scohe001 Jul 31 '13 at 16:56