I have a non-open-source GUI program on OS X which has a menu button to open a file in one format (example.X), and another menu button to export a rendering of that file in another format (example.Y). This is not a conversion that could be done by myself or by any other tool I've found, as the rendering involves extensive digital audio synthesis.
I have a folder of 100 files of type X, and I want a convenient way to convert each .X file into a .Y file without manually opening and exporting each in the GUI. Literally just two simple commands which don't require interfacing with the GUI - one to open the file, and another to render it out.
Is there a general way to achieve the effect of opening a program, running some commands from the menu, and then exit via the command line?
Thanks!
Related
I'm trying to build a command line script to automate a process. Most of the script is straight forward, but there is one part where I need to convert a file from one format to another.
Unfortunately, the starting format is propriety and only one Windows software program supports this file type, and that program is only controllable via a GUI.
What I need to do in the GUI is simple:
open the program (if it is not already open)
file > open > [file]
(let file fully load)
file > export> xml > uncompressed > export > [give name] > save
(wait until finished)
(proceed)
Is there a way to work a GUI program into a command line script? How would I start? Would I need a dedicated computer that no one uses for this process?
Yes, there is a way to power a GUI program from a script: autohotkey (AHK). In short - though this summary trivializes its power - think of AHK as a way to send keyboard shortcuts to Windows and the program:
Windows + R to open the Windows Run... dialog
Type: program and press Enter
Seize Window of program
Alt + F to open File menu
etc...
So, you write an AHK script to do the Windows interaction, and you invoke autohotkey with that .ahk file as part of your pipeline.
As for needing a dedicated computer? I'd recommend it. But, if you have just one metal box, spin yourself up a VM and run your pipeline inside of that -- that leaves the primary OS available for interaction, while the VM does the load lifting.
I'd like to create a program which uses certain information given by my program's users and bakes this info into executables which can be used with Mac's "Open with...".
Since bash scripts cannot be used directly for Mac's "Open with..." functionality1, however, I'd like to find a way to wrap such a script (and as painlessly as possible).
I am aware Automator lets one build applications which include bash scripts and which work with "Open with...", but I want to be able to programmatically build both the script and the containing application (and I haven't found that Automator can accept command line arguments to compose applications).
What are some simple, lowest common denominator/open format approaches (without using Python, etc.) whereby I can do this (ideally in a way that could work on Linux as well)?
I found I was able to build an AppleScript application programmatically using osacompile (or apparently also possibly using Apple's JavaScript) using on open listener to listen for "Open with...", default file association, or dragged files (including when placed on the dock) and an on run listener to work with command line invocation. I could then use do shell script internally to invoke my desired file (in my case, calling the Node.js binary with a Node script and some arguments).
I was also able to do try/on error check for an input and if none were present do a choose file with prompt (specifically choose file with prompt "Prompt message" of type {"js"} for JS files) so that the application could be double-clicked without a file argument but yet trigger a file dialog (e.g., for use on the dock).
Is it possible to display a .txt file that has been just created by Matlab ? Basically make it pop up and become an active window (not in matlab, but open the text file as if you are opening it from a folder). If so, what is the code to accomplish that ? Using a MAC OS.
Perhaps system('notepad filename.txt') on Windows and system('open filename.txt') on Mac. When you use open, the OS will automatically use whatever application you have set as default for that file type. If you want to open it in a specific editor that is different from the default, replace open with the correct command (if on the path) or use the -a flag to open as:
system('open -a /full/path/to/application filename.txt')
I want to create an application on a Mac to convert multiple files (txt, pdf, doc, html, etc) to a single pdf file that can be printed. The real point is that if you have 50 texts you don't have to open every single file and click command-p.
I'm not quite sure whether the best way to do this is by creating a full-fledged app or an automator plugin (or something else). If I remember correctly there's a filter in mac os's terminal that can convert files to pdf (but I forgot what it's called).
So would an automator plugin do this well, or shall I make an app for this? Can you provide me advantages for each answer?
I've done cocoa touch programming before so I can write objective-c quite well.
Use appscript, either as an action in an automator script or standalone. The advantage is that it is very simple and will take you a fraction of the time to write an app.
Here is something very close to what you want. It sets up a drop-folder and each file dragged onto it is printed (you can use multiple-select to get what you want). It uses Apple Works 6 which doesn't support the file-types that you want.
To modify it to use the Preview application instead you need to change the tell command in the script and then google the dictionary for Preview to check which verb to use for printing.
I'm creating a small ruby script to resize images and save them in a specified directory. I'd like the application to be as transparent as possible.
Is it possible to allow file dropping onto my Ruby script in all platforms? For instance, the user drags a file onto the script, which then takes the file path as an argument and resizes the image accordingly -- No GUI, no console, etc..
The behavior of drag & drop is dependent on the OS (and in case of Linux of the Window Manager), so no.
In Windows, you get the behavior you want for free. Just put a .rb file on the Desktop, and the files dragged onto it will be arguments to your script.
Another easy way for integrating with Windows is to write to registry entry HKLM\Software\Classes*.jpg\myhandler\command with the command you want to appear in the context menu of Windows Explorer (right click on a jpg file will popup a menu which will have your script in the menu).
I don't use drag & drop at all in Linux, so I wouldn't know how to do that there. I would expect it to have more security issues (permissions must be right, ...) but you could get there by creating a .desktop file, see http://standards.freedesktop.org/desktop-entry-spec/latest/ for the complete standard, or read some examples from ~/Desktop/*.desktop .
Platform dependend, so here for windowsusers and reference only.
Save the following to a .reg file and load it by doublecliking it, tested on Windows Vista and 7
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\rbfile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\rbwfile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\RubyFile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
[HKEY_CLASSES_ROOT\RubyWFile\ShellEx\DropHandler]
#="{86C86720-42A0-1069-A2E8-08002B30309D}"
Such behavior would surely be platform specific, as drag-and-drop is implemented by the OS in this case, not by ruby.
So answering your question: no, it is not possible.
You can use platypus on os x to create a wrapper around your script.
http://sveinbjorn.org/platypus
regards
Claus