Skip to content

Add in a short delay when opening the terminal on OSX #4197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

staticfloat
Copy link
Member

Allows for users with ~/.bash_profile setups that open tmux, screen etc.. by default to launch the Julia app properly.

See #3547 for discussion. A better implementation would be a command to Terminal.app to not start a shell that reads these customized scripts, however a search for such a command has been unsuccessful.

Allows for users with ~/.bash_profile setups that open tmux, screen etc.. by default to launch the Julia app properly.
See #3547 for discussion. A better implementation would be a command to Terminal.app to not start a bash login scrip, however a search for such a command has been unsuccessful.
@andrioni
Copy link
Member

The Julia binary on OS X always opens on Terminal.app? Or it uses something like xdg-open to determine which terminal emulator to use?

(I've never used the pre-compiled binaries, but it would be pretty weird for me to see Terminal.app launching instead of iTerm 2)

@staticfloat
Copy link
Member Author

Yes, it is always Terminal.app. I'm not sure what the invocation for open (the OSX version of xdg-open) would be to startup the default terminal emulator; but if you know how to do it, I'm all ears!

@JeffBezanson
Copy link
Member

I don't understand this change.

@staticfloat
Copy link
Member Author

On some user's platforms, they have a ~/.bash_profile that executes a lot of commands at startup. Because of this, when the AppleScript is run, it spouts the incantation to start Julia into the terminal when user input is being ignored by those auto-run commands. This delay gives a reasonable safety margin for ~/.bash_profile commands to finish before attempting to start up Julia.

An example of where this occurs is anytime a user has a program such as screen or tmux auto-starting in a new terminal.

@JeffBezanson
Copy link
Member

Hmm, not too satisfying. The .5 second is arbitrary of course. It seems strange for applescript commands to fail if the target app is not "ready" for them; you'd think that happens all the time, e.g. the app being busy computing something or not having started up yet.

@staticfloat
Copy link
Member Author

Yes, it is entirely arbitrary and unsatisfactory.

It's not the Applescript that fails, it's because tmux, screen and other command-line programs throw away standard input they receive between the time you invoke tmux and tmux invokes another shell. If I open a shell and start typing immediately, I'll lose the first character or so every now and then.

@simonster
Copy link
Member

At least in 10.8, Terminal tabs have a busy property that you can use to determine if something is running. The following AppleScript returns true if there is a process executing in the frontmost tab:

tell application "Terminal"
    busy of tab 1 of window 1
end tell

This corresponds to the spinning indicator on the tab. I'm not sure exactly what heuristic this uses, but it returns false when screen is running. You might just be able to keep checking this property until it returns false and then run Julia.

@staticfloat
Copy link
Member Author

That is a really neat idea, unfortunately, it doesn't work reliably. I don't think the busy marker queues off of exactly what we need it to. :(

@vtjnash
Copy link
Member

vtjnash commented Oct 6, 2013

does this script work any better?

tell application "System Events"
    tell process "Terminal"
        activate
        tell menu bar 1
            tell menu bar item "Shell"
                tell menu "Shell"
                    click menu item "New Command…"
                end tell
            end tell
        end tell
        tell window "New Command"
            set theCheckbox to checkbox "Run command inside a shell"
            set checkboxStatus to value of theCheckbox as boolean
            if checkboxStatus is false then click theCheckbox
            set theTextbox to combo box "Command:"
            set value of theTextbox to "julia"
            click button "Run"
        end tell
    end tell
end tell

@JeffBezanson
Copy link
Member

Can somebody with a mac please try this? cc @StefanKarpinski @ViralBShah

@staticfloat
Copy link
Member Author

@vtjnash Sorry, this slipped through the cracks a bit. That fails to run on macs without the "Assistive Devices" checkbox checked in System Preferences. With that setting checked in System Preferences, the situation is improved somewhat; users with a ~/.bash_profile like myself will have tmux come up with a new shell, and when tmux is quit Julia is run. So one small step forward I suppose.

@JeffBezanson
Copy link
Member

Closing since this PR is not a sufficiently satisfying solution. We can try other approaches during the RC period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants