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).
Related
I managed to make Firefox to follow specific protocol links (oxygen:/...) and use an application to open them. As the Mac OS X oXygen XML Developer app doesn't accept arguments, I need to use a shell script that is shipped together with oXygen itself. Given Firefox doesn't like shell scripts, I needed to write an Automator application 'Run Shell Script'. As I was having trouble to get it to work, I decided to use a stub code, with osascript, just to debug variables.
My current script looks like:
osascript -e 'display alert "'"$1"'"'
and it is defined as a bash script, receiving data as arguments.
When I click the link the dialog of osscript appears, but with an empty message. So, I am not sure how the URL is being passed to the application itself. I tried, also, with receiving data as stdin, but with no lock. I got to the point of writing a script that dumped all the parameters and STDIN to a file, but it ends up always empty.
Thank you for any hint.
I have custom Alfred workflow to File Filter some folders of my choice. I have two actions - to browse with Alfred, and, with CMD modifier, to open in Sublime.
I want to have an action where I may choose which program I want to open it in. I use 2-3 programs for basic editing, so I want to be able to select one of these.
Workflow would be:
start my workflow
enter few chars to find file
select a file with CMD
choose editor of choice from the list
How to implement the last thing? In other words, how to implement incremental actions e.g. "do this with this and then this".
There're two ways to do it.
Because you can choose which application will be used to open the file instead of the default one. A simple idea is using different keyword for each application. e.g. vim [file-name] for vim while sublime [file-name] for sublime.
Another way is using Run Script instead of Open File. An Apple script or Bash script can get the result in File Filter and open different application as you wish.
This may be a basic question. I have written a small perl script to run on a Mac running OS X which can be called from the finder by double clicking in the normal way. The file is executable and contains starts with #!/usr/bin/perl and input and output is via the clipboard. This all works but automatically opens a terminal window which the user must then close once execution is finished.
Is there an easy way to run this program as an application without opening a terminal? Can one do this with the native OS X perl? Or do I need to download something? Since the program will also be used by other users, the simpler the solution to better.
With the application "AppleScript Editor" : open it
Copy/paste this script
tell me to path to resource "this Name.pl" in directory "Scripts"
do shell script (quoted form of POSIX path of the result)
In the first line, change the name "this Name.pl" by the name of your perl file.
Save as --> Application
In the Finder :
Copy your perl file (executable) to the folder "/Contents/Resources/Scripts" of the created application
For Win32/Linux/or Mac use http://www.cavapackager.com/
If you're distributing your application to others, Platypus includes an installer to build free-standing apps around scripts.
Platypus supports Perl, Python, PHP, Ruby, Swift, Expect, Tcl, AppleScript or any other user-specified interpreter. It is free, open-source software distributed under the terms of the three-clause BSD license. It can run silently (without opening a terminal window, as you require), or can display graphical feedback of script execution as progress bar, text window with script output, droplet, WebKit HTML rendering or status item menu.
I have written a Windows software and I have associated a file extension with this program. When I double click a data file then my program starts up and opens the file. So far it works. But when I select multiple files and then click "Open" in the context menu then multiple instances of my program are started, one instance for one file. I want Windows to open ALL files with a single instance of my program. Is this possible without implementing a one-instance-handler in my program?
Currently the MyFileType/shell/open/command in the registry looks like this:
"C:\Program Files\MyApp\MyApp.exe" "%1"
Maybe there is some special Token/Variable I have to use instead of the "%1" to get it working? On Linux I have to use %f for a single file and %F for a list of files. Is there something similar on Windows?
The simplest way is to associate your app with the default shell verb (e.g. “open,” or “play,”) for the file type, and implements a drop target that uses SHCreateShellItemArrayFromDataObject to get the selected files. Suggested reading: How the Shell Invokes Verbs
If you don't like to take over the default verb, you can add your verb to the file association's open with list.
Another method is to make your app a singleton and send the document's path to the first instance via inter-process communication methods such as DDE or RPC. This requires you to keep your main window responsive (for example, won't work if you are showing a dialog)
%* might be what you're looking for.
I am from a windows background and trying to help a mac user friend to backup her pictures, docs, etc. onto an external drive. In windows, I would accomplish this by creating a simple batch file with an xcopy command and have a shortcut on the desktop that pointed to that .bat file when double clicked. However, in the mac world I am having significant trouble finding how to do this. I have searched repeatedly to find the mac equivalent, but all I find are sites saying things like "there are so many options on a mac - use one of them." However, none have ever given a specific solution nor pointed to a specific solution. Anyone here know of a specific step by step process to accomplish this? I simply want to be able to have her double click an icon on the desktop and have it copy her personal documents (not application settings or other overhead) to her external hard drive. Any help would be appreciated.
Create the batch file, which is usually called a shell script.
Enter all the commands that you want to run.
Set the executable bit, this is done with chmod +x path-to-the-file in Terminal.
Show info for the script and set Terminal to the application which should open it.
However, what I've done in similar situations and that I would recommend that you do is that I've created a shell script and instead of using Terminal I've initiated it from an AppleScript application. You can of course embed the entire shell script in the AppleScript as well. Basically it will look something like the following:
on run
do shell script "rsync -av ~/Pictures /Volume/Backup"
end run
Repeat the do shell ... line for each folder that you want to copy, or call the shell script itself. Then use AppleScript Editor which is included with Mac OS X and save it as an actual application.