Mac-Automator, How to pipe the output of a shell script to a GUI text box - user-interface

The problem I face is this:
I would like to have in a context menu (when i right-click on a folder) an action to be executed and display the output to the user, inside, let's say, a text area window with a vertical scrolling bar. Suppose, that the action is just a shell script that executes a "find" command inside the given directory, searching for a specified pattern.
I have managed to implement it, up to this point, using Automator. What I cannot do is to pipe the output in a synchronous fashion (what is meant by "synchronous" is to have the output print to the user when is produced by the "find" command, and not after the command has finished) in a GUI.
I have spent sometime searching on this and I have come to the conclusion that XCode and Interface Builder have to be put into the play? Am I on the right track? Is there a straightforward and simple way in succeeding in this without having to dig into this framework?
Thank you very much,
Babis

You can have the shell script throw a dialog when it gets the result using http://cocoadialog.sourceforge.net/

Related

Run AppleScript progress bar in separate window from command line?

To display dialogs from the command line I just use
$ osascript File.scpt
However, the progress bar feature isn't constrained to a dialog window because it adapts to the current application, e.g. a Finder window, where the progress updates are shown on the bottom of the window. File.scpt would look something like this.
set numUpdates to 100
set progress total steps to numUpdates
set progress completed steps to 0
set progress description to "Updating..."
set progress additional description to "Preparing to process."
set cycle to 1
repeat with a from 1 to numUpdates
# update description, completed steps, etc
end repeat
When I run my script from a terminal window, however, the script runs but nothing is shown to indicate the progress. Is there a way to force the progress bar to open as a new dialog or something along those lines without having to export the script as a ".app" file?
The reason Script Editor can display progress in its window and Terminal cannot is because Script Editor has its own extended scripting definition with the extra functions so when the script is run via script editor it has been programmed with the extra progress indicator but no other applications are sorry. The way I see it, you pretty much have 2 ways I can think of that will let you display "Progress" in AppleScript:
This is kinda ugly but I used to just have a transparent spinner gif file that will be displayed in a dialog which will give the affect that something is loading or working. and a single button saying Nothing or OK eg.
display dialog "Loading..." buttons:{"OK"} with icon ("/path/to/loader.gif" as POSIX file)
And if you wanna make it temporary just add giving up after (duration in seconds)
This is probably the best option but it is probably more complicated. I advise that you transfer to a programming language called "AppleScript Objective C" otherwise known as "Cocoa AppleScript". This allows you to use the basic AppleScript commands with Cocoa Windows/Dialogs/etc including progress bars!. to start you off you should download Xcode and research AppleScript Objective C and perhaps stick to it. Its better than AppleScript but still has the same functions :)

How to use WaitForCursor?

I'm using WaitForString command to pause my script until the desired text appears on screen. However I notice that the screen stops "printing" as soon as that happens. I'd rather wait until the whole screen finishes refreshing.
I suspect that instead of WaitForString("text"), I could use WaitForCursor; when the screen is complete, I can use Get("text").
However, I cannot find any documentation that explains the WaitForCursor command. How would I use it in this case?
Have a read through of this manual for secure-crt and scripting with vbscript
Scripting Essentials (PDF)
I expect you would use the command itself as crt.Screen.WaitForCursor(timeout) although I've never used this software myself so that's just a guess

ctrl-r history search equivalent for R64/R GUI OS X Application [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Retrieving Variable Declaration
I would like some way to search through the history of commands sent to R for a running session. This can be done in Bash using ctrl-r history search, and I find it extremely useful.
Is there a shortcut key in the R GUI IDE that does this? I've looked through changelogs and done some google searching, and I can't find it.
If not, is there a way outside of the R GUI IDE to extract this information? Possibly by searching through some sort of .Rhistory file maybe?
How are other R users accessing command history?
In the R GUI there is is a discoverable side panel that appears to whichever side of the screen has the most space and it has the history entries displayed in a clickable manner. That panel is kbd-toggled with shift-cmd-H, and if opened that way will place the active cursor in an entry line. That line at the top of that panel accepts regex expressions that will limit the displayed lines to those that match. It's a bit confusing (to me anyway) that there are separate history files. The side panel like the R.app or R64.app uses a file named ".Rapp.history", while the regular history file that a Terminal R session would access has its expected name.
The icon that does the show/hide toggling is exposed to the toolbar item selection panel of the console, so I suspect it is exposed to AppleScript commands. I'm not a big user of AppleScript and that last part is a hunch more than a promise.
The MacOSX FAQ says R will accept Applescript delivered R commands.
What is available as a shortcut depends on what interface you are using. If you use the r terminal on windows (but not the GUI) then ctrl-r works like you describe.
One tool (though not as easy) that should work for all interfaces is to use the 'history' command. Y can type something like history(pat='plot') and the recent commands that included "plot" in them will be displayed and you can cut and paste to rerun the command of interest.

Command that launches a graphical text input box that outputs to stdout

Is there such a program that can open a little input box and send the input to stdout? If there isn't, any suggestions for how to do this (maybe python with TkInter)?
If you're looking for something that works in text mode, then dialog or whiptail are two options.
The oldest would probably be dialog. Another example of such a program is Zenity and another would be Xdialog (all pretty much replacements for dialog).
They tend to do more than just accepting user input, and you can create some fairly complex GUI dialogs with them, but are simple enough to do what you want very easily.

Vim Question Regarding Views

I have been reading a lot of the questions here on vim. I can't locate something that I want to do with vim but I am sure its possible.
I like vim(I am still new at it) using tabs and I have adjusted my vimrc so that H & L keys take me back and forth between tabs.
I was hoping to find a way to be able to use tab commands to open up a tab as output, so that if I am writing something in my case Ruby and I want to test it I could run it and flip to a new tab with the output. Or flip a tab to an interactive console to test code. This is possible?
As an aside is it possible to expand tabs to views so if I had two tabs open say script and output I could :spx or similar and have tabs come to split screen.
You can load the ruby output into a vim window in a couple of ways. One way would be to open a new split window and then load output of command:
" vimscript command to open new split window
wincmd n
" run ruby command and insert output at line 1
1,1!ruby foo.rb
alternatively you could get view the output on a new tab with a single window:
tabnew
1,1!ruby foo.rb
I know it's not the answer you want, but use buffers and ditch the tabs. I have a screencast going over how to use splits to manage your window.
http://lococast.net/archives/111
As for the ruby output, that seems like it might be covered here:
https://superuser.com/questions/133886/vim-displaying-code-output-in-a-new-window-a-la-textmate
In answer to your question about opening up a tab as output, I don't think there's any built in way to do this. There's the RunView plugin (see my answers to this question and this one), but I don't think that it supports using a separate tab (it works with a split window: what I think you refer to when you say 'view').
Regarding an interactive console: no, this is not possible. See :help design-not.
As for general use of Vim, try to get used to the idea of buffers and the fact that each 'view' (my term), whether it be a split window, a tab or whatever is just a means of looking at a particular buffer. You can have multiple views on a single buffer, so you can have a source file vertical split with two headers in one tab and the same source file vertically split with another header and a different bit of the same source file in another tab. This is very powerful once you get used to it. The Ctrl-W keyboard shortcuts are your friend (e.g. Ctrl-W, h to go left one window).
As for changing a tab into a split window, I don't think there's a direct way to do this (how would Vim know which tabs you wanted to join?). You can break a split into a tab with Ctrl-W + T, but to go back you'd have to create a couple of mappings. This is off the top of my head but something like this might work:
command! TakeThis let takebufnr = bufnr("")<CR>
command! SplitTaken exe 'split #' . takebufnr<CR>
nmap ,t :TakeThis<CR>
nmap ,s :SplitTaken<CR>
Then press ,t on the buffer you want to grab and ,s on the one you want to split with the 'taken' buffer.

Resources