OSX bash - window focusing on launched executables/apps? - macos

If i launch a executable/another app from a bash script, this executable/app starts up normally, but with it's application window not in focus.
If you launch the script from a window for example, the bash script calls upon the other executable/app, but you can't see the app's interface because it gets launched below all windows.
For Linux there exist some window managers that can do this, like these tips here:
Is there something for OSX as well?
I realize i can set the active window via AppleScript (osascript via bash), but i wanted to do this without AS.
("tell application \"newapp\" to
activate")

My appswitch tool does exactly this.

Related

Minimalist cocoa app, how to create a menu bar?

I’m just trying to create a window in cocoa. I wanted to use this code as a basis but somehow the app menu does not show up (still shows the one from the terminal, un-clickable though).
Can anybody give me a hint what might have changed in cocoa since that article was written? I’m using Yosemite.
It works fine for me, but I had to Cmd-Tab switch away and back again to the running executable before the app menu became active. I tried appending a space and the ampersand symbol to the end of the code, which tells the shell to background the task, thinking it may launch normally then, but to no avail.
You might try appending an AppleScript command such as tell application MinimalistCocoaApp to activate after the command to launch ./MinimalistCocoaApp (separated by a semicolon). I'm not sure the "compile and run" terminal command for AppleScript, but that should be easily Googled.

Pin OS X Terminal to the Desktop Background

I am looking for a tool that can 'stick' the OS X terminal app to the desktop background. I want it to be below the desktop icons, on top or instead of the background image.
I am using the terminal through out the day, from time to time. But I don't really need it for ongoing tasks, only to check something very fast. So having an active corner that shows the desktop would be the ideal guesture to reveal the terminal.
GeekTool has the ability to present the output of a terminal command on a desktop, however, I haven't been able to type something into the terminal overlay, GeekTool is showing. Is there any other tool, that could achieve that?
You can use the stock Script Editor app to save the following script as an application (.app file):
tell application "Terminal"
do script "cd ~/Desktop"
end tell
You can edit the script above to specify the directory you want the new window to use by default.
Once you've created your .app file you can put it on your desktop and conveniently double click it to open a new terminal window.

Why does the safari app gets launched when I open apple script?

I have an applescript. The script goes like this..
tell application "Safari"
open location "http://www.google.com" -- mentions the perticular webpage to be loaded
activate --makes the Safari application the front most application
end tell
Whenever I open this script, the Safari application gets launched. To be very clear, I'm not running this application instead I am just opening this script in applescript editor.
Can anyone please explain me why the Safari is getting launched. The Safari gets launched but it will be hidden or say it does not put up any window. [Neither it does load any pages in the background, it just gets launched in the dock and a dot saying that the app is launched will be present].
Once I run the script then the safari puts up the window and loads the desired web-page.
Please Help.
In general, applescript must launch an application to learn what commands it understands. Over time applescript has gotten better at not launching applications for this task, but some apps still get launched. iPhoto is one I notice gets launched when I open applescripts that use it. As such it's not something you can avoid.
However, in your case there may be a fix. The "open location" command is a generic applescript command. You do not need to tell Safari to execute that command. Therefore you can probably change your script to this and avoid the launching issue. The open location command should just open the link in your default browser which I assume in your case is Safari. It should also automatically activate it for you.
Good luck.
open location "http://www.google.com"

Launching a program so that it opens in center of the launching application

Launching a program so that it opens in center of the launching application.
Platform: Mac
Launching mechanism: a c++ program launches using system()
Currently I observe the program launched pushes it to left most part of the screen.
Launching a program so that it opens in center of the launching application.
On Mac OS X systems, programs don't launch into a specific area of the screen. When they launch, they become the "front" application, and take over the menubar area with their own menus. They may choose to open a window after they have opened, or not.
Find out if the program in question accepts apple events / applescript commands. If so, you may be able to ask the program to position a window in a particular location.
Also, if you still have to use system, you can send apple events with the osascript command.
If you're using system, there's really nothing you can do, since you've implicitly delegated everything about the process except its startup args to the OS. There may be ways to accomplish this using other OSX-specific APIs, but not with the parameters you've outlined here.

How to start a process from another application and then open a terminal to that process in gnu screen

I'd like to be able to launch a process from a GUI application (right now I'm thinking specifically of letting an eclipse user -- possibly via a plugin -- click a button to launch a build using my organization's build system).
I don't want this process to stop when I stop the parent application, and I want to be able to "switch into it" later, as though I launched it from a command line.
I've seen GNU screen described as good for most of what I'm asking for, but I'm not sure about the "launch the process from another application" part.
Can this be done if the GUI application was itself launched from within screen? Can this be done if it wasn't? I'd be very interested in seeing how!
Update:
Prepending "screen" to a command line looks like a good way to start a process in screen from a shell, but I'm trying to find a way to do this without being taken straight into that session. I want to "send" the command to a screen session, where it will be started in a new window in that session.
simply prepend the 'screen' command to your normal commandline.
E.g. if you normally execute "./make_build.sh opt1 opt" then your screenified commandline would be "screen ./make_build.sh opt1 opt2"
Its that easy! :-)
You can send screen messages to a running screen session with the -X flag.
See How to start a new process in a new window in an existing GNU screen session, from outside the session or the screen man pages.
If you can suspend the process (via Cont-Z) you can then run
screen -dr -X screen $(fg)
It will attach that process to a new window in the screen. Its not ideal, but it will work.

Resources