Going bananas trying to write a very basic macro to simply open a specific file

Hello,

Let’s say that I have a specific file with a set path:

/Users/bromlin/Documents//P-touch Editor 5.0/Diltex Shipping label.lbx

which I always open with the application called PTouch

How do I write a macro to do so, ie open that specific file (a label that I print out)?.

I spent an hour fishing through all possible actions, but can’t find a simple ‘open file’ command. I don’t need to select via Finder, because I already know the file name and path.

Follow up question: would it even be possible to design a macro to complete the whole procedure, it also print the file Cmd-P in Ptouch after loading the file.

Thanks very much for your time and help,

Hi Ronald

You need to use the Open a File, Folder or Application action.
See below.

I have also changed your path to use the tilde for your home directory. This makes the macro more portable.

Keyboard Maestro “Open a File, Folder or Application” Action

Hello Jimmy,

you are very kind. thank you very much.

If it is not asking too much, is there any way to complete the whole procedure, ie open the file, (as per your instructions), print Cmd-P + Enter, and put the application PTouch in the background.

Ronald

These two Actions should do the trick:

Type a Keystroke

Hide a Specific Application:

It defaults to the "Finder", but you can then change it to your app.

You may also find this info helpful:

Getting Started with Keyboard Maestro

  • Read the Quick Start.
    • This is essential to become familiar with KM terminology
  • Do the tutorial (Help ➤ Tutorial) in the KM Editor.
    • Gives you a live walkthrough of creating a macro in the KM Editor
  • Review all available Macro Actions
  • For Help with an Action in your Macro, click on the gear icon at the top right of the Action, and select "Help"
  • Start small, and grow your macros organically.
  • Be prepared for some trial and error in the beginning.
  • Make good use of this Keyboard Maestro Forum
    • Search for existing macros
    • Post your questions/issues if you get stuck

thank you very much !!

The trickiest part in making this macro robust is going to be the timing.

Opening a document will take some time, and it’s difficult to know how much.

For a fixed document like this, you can probably do something like Pause Until Front Window title contains “Diltex Shipping label”, then simulate the Command-P.

Typically that will produce a print sheet, so you need to allow for the animation time of that, and then perhaps control that or just simulate a Return to print it.

Knowing when the print is finished would be tricky too, but you probably don’t care, just hide PTouch at that point and it can print while in the background.

A message from The Man himself !!!
thank you very much for your reply.
I purchased KBM a few weeks ago: you are a genius. There is no other word. Can’t believe that I have not had this software years ago. Probably because reviews classified it with ‘application launchers’, so I arbitrarily chose Butler, which is a nice app, but nothing like KBM.
KBM is a pure delight. Thanks very much and keep up the good work!

1 Like

Peter is right (of course). You often have to tweak a macro to get the timing right for your system and apps. Two key Macro Actions I use for this are:

  • Pause for n.nn Seconds
  • Pause Until Conditions Met
    • like "front window title" is or contains ...
    • or "front window of app TBD exists"

Here is an example of a real macro I use many times a day:

##Macro Library [TW] Copy Current Selection to TextWrangler
####Download:
[TW] Copy Current Selection to TextWrangler.kmmacros (6.9 KB)

Some of the "Pause n.nn Seconds" may appear unnecessary or too long to some, but they are there because I found I needed them after using this macro for a while. I tend to be conservative and provide longer Pauses than absolutely necessary just to make sure it will work. It doesn't bother me to way an extra 0.2 of a second to get it right.

YMMV. Tweak the timing for your needs and preferences.

1 Like

Thank you very much for your comment.
I had a problem, and it was solved by pause, as you suggest. I am very grateful
I will look into the until conditions met function. It seems very interesting.
cordial regards

Um, this is a built-in feature of OS X, has been since day 1, but hardly any one knows about it :smiley:
(It has been too long but I think it was even a feature in OS 9 :open_mouth:)

Select the document in the Finder (but don't open it) and press Command+P. It will open the document with the default app, print it, and close the document. Tada!

A few things to be aware of

  • It doesn't quit the application after it has sent the document off to the print queue

  • It uses the current preset for the print options so you will need to open the document, choose the print option to show the dialog, set any special printing options you need, then save it as default or choose the "Last Used Settings" option as the default.

  • It will use the default printer. If you have only 1 printer, you are fine. If you have more than 1, open the System Preferences > Printers pane, select the printer you want to use from the Default Printer pulldown menu at the bottom. The default setting is "Last Printer Used".

If you don't want to open the folder to select the file, you can make an alias of it on the desktop. Command+p works on aliases too!

If you don't want to even have to select the file at all and make KM do everything for you (and who doesn't want that?), set up this macro as a global shortcut (like Ctrl+Shift+P) and you can print a label anytime!

2 Likes

Hello Onan, fantastic answer ! thanks very much for the tip !