문제

I am trying to setup a TextWrangler script that automatically sends selected code to Julia. Copying a bit from a similar script that does the job for sending code to R I tried the script

tell application "TextWrangler"
    set the_selection to (selection of front window as string)

    if (the_selection) is "" then
        set the_selection to line (get startLine of selection) of front window as string
    end if
end tell

tell application "Julia-0.2.1"
    activate
    cmd the_selection
end tell

It does not work. Probably because of the line containing "cmd the_selection". Anyone a suggestion on how to fix this?

도움이 되었습니까?

해결책

Well if Julia isn't scriptable as @khagler says, then you can usually use gui scripting. This will work as long as Julia has an edit menu and the keyboard shortcut for paste is cmd-v (like in most applications) and your cursor is placed in the proper location for the paste to work. Good luck.

tell application "TextWrangler"
    set the_selection to (selection of front window as string)

    if (the_selection) is "" then
        set the_selection to line (get startLine of selection) of front window as string
    end if
end tell

set the clipboard to the_selection

tell application "Julia-0.2.1" to activate
delay 0.2
tell application "System Events" to keystroke "v" using command down

EDIT: I see in your comments that a new Julia window opens every time the script is run. That might be happening because of the line... tell application "Julia" to activate. You might try this line of code in its place. It's another method to bring Julia frontmost before issuing the keystroke commands.

tell application "System Events" to tell process "Julia-0.2.1" to set frontmost to true

Note that if this doesn't bring the Julia window frontmost then it's because the process name is wrong. Sometimes the process name is different than the application name. If true you'll have to figure out the name of the Julia process which you can do by running this and finding its name. You may have to use "Terminal" if Julia runs in a Terminal window.

tell application "System Events" to return name of processes

다른 팁

Julia is not scriptable, so you won't be able to send your code this way. You could try this:

do shell script "julia -e '" & the_selection & "'"

This is equivalent to typing a command into a Terminal window. Depending on what exactly is in your selection, you might need to save it as a file first and then pass the file path instead. Also, note that if julia is not in your path (as would be the case if you just copied the Julia app to your Applications folder) you'll need to specify the full path to the actual executable within the .app package: /Applications/Julia-0.2.1.app/Contents/Resources/julia/bin/julia.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top