Copying a file name and pasting into different application

Hello!

New KM user here, so please excuse the amateur question.

I work in two different music application programs.
One of them is notation and the other is recording.

I'm trying to build a macro that will copy the file name of the currently open application and then open the 2nd application, create a new file and do a "Save As" and paste the file name from the 1st application.

Could someone point me in the direction of how to create a macro that would accomplish this?

Thank you!!

Hi @abw89, welcome to Keyboard Maestro (KM) and its Forum.
KM is one of the best Mac automation tools available, its Forum is one of the best and friendliest forums on the Internet. Whenever you reach a tough stumbling block trying to use KM, please feel free to post your question/problem here for help.

You will find this helpful:
Tip: How Do I Get The Best Answer in the Shortest Time?

Now, to your request.
Your requirements statement is actually very good. Thanks for that.

The hardest part is getting the file name of the file currently open in the first app.
I don't have either of these apps, so I can't test or inspect them.
The best method is to use AppleScript with the App's scripting dictionary, which it may or may not provide. You will have to investigate to find out.
If the App does not provide a SD, then we can use UI scripting, as shown in this macro:

Macro: Finding the File Path for the Front Document in the Front Application by Chris @ccstone

So here's an example macro to help get you started, that used the UI scripting method.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Get File Name in App 1 and Use in New File in App 2 [Example]

-~~~ VER: 1.0    2020-10-31 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Get File Name in App 1 and Use in New File in App 2 [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX (uses script by @ccstone)

PURPOSE:

  • Get File Name in App 1 and Use in New File in App 2
    • Only the Base File Name is used (no extension)

HOW TO USE

  1. First, make sure you have followed instructions in the Macro Setup below.
  2. Select/Activate App 1
  3. Trigger this macro.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .

Make These Changes to this Macro

  1. Assign a Trigger to this macro.
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro, and the Macro Group it is in.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • Activate 2nd App (CHANGE to Your 2nd App Below)
    • Create New File in 2nd App (CHANGE If Needed)

REQUIRES:

  1. KM 9.0+ (may work in KM 8.2+ in some cases)
  2. macOS 10.11.6 (El Capitan)+

TAGS: @Files @FilePath @AppleScript @Example

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

==USE AT YOUR OWN RISK==

  • While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

1 Like

Hello!

Thank you so much for your help and assistance with this macro.

When I ran the macro, I received an error: "Macro canceled due to script error" and "Unable to get File Path currently open in Digital Performer app. Digital Performer is the 1st application whose file name I am attempting to copy.

However, I ran the macro again with a different application at the front window that was something basic, such as Preview, and the macro worked.

How can I troubleshoot the AppleScript to get the file path of my recording application, Digital Performer, and avoid this error?

Thank you again!

Sorry to hear that. Since I don't have the Digital Performer app, I am unable to test, inspect, or offer much advice.
Do you have a manual way of getting the file path (or file name) from DP?

Not at the moment, but I will look further into this.

Thank you very much for your help!

Here are two ideas. Both less than optimal, but may be workable:

  1. Use the File > Save as to display the save dialog with the current file name highlighted. Then copy that:
  2. Use the Window menu to see if the current file is listed with a checkmark, and then get that:
    • image

Yes, both ideas are possible with the app.

Can this be written into the AppleScript or should I try with KM actions?

@abw89, I just tried this method and it seems to work well.
Please give this revised macro a try:

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Get File Name in App 1 and Use in New File in App 2 [Example]

-~~~ ==VER: 1.1==    2020-11-01 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

  • ADDED 2nd method to get original file name IF the script could NOT get it.

DOWNLOAD Macro File:

Get File Name in App 1 and Use in New File in App 2 [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Get File Name in App 1 and Use in New File in App 2
    • Only the Base File Name is used (no extension)

HOW TO USE

  1. First, make sure you have followed instructions in the Macro Setup below.
  2. Select/Activate App 1
  3. Trigger this macro.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .

Make These Changes to this Macro

  1. Assign a Trigger to this macro.
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro, and the Macro Group it is in.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • Activate 2nd App (CHANGE to Your 2nd App Below)
    • Create New File in 2nd App (CHANGE If Needed)

REQUIRES:

  1. KM 9.0+ (may work in KM 8.2+ in some cases)
  2. macOS 10.11.6 (El Capitan)+

TAGS: @Files @FilePath @AppleScript @Example

USER SETTINGS:

  • Any Action in magenta color is designed to be changed by end-user

==USE AT YOUR OWN RISK==

  • While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

It works!

Thank you again for your help!

1 Like