Optional auto execution of command / macro on startup

You have encountered a problem using Far Manager? Here you can get help.
Post Reply
kamil
Posts: 29
Joined: Fri 13 Apr, 2012 19:19
Has thanked: 1 time

Optional auto execution of command / macro on startup

Post by kamil » Sat 27 Apr, 2019 14:14

When I'm starting Far, I want to decide (on the command line) to auto-execute a macro.

Something like flags = "RunAfterFARStart", but optional - controlled from the command line.

Is it possible?

Shmuel
Posts: 5727
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 21 times
Been thanked: 203 times

Optional auto execution of command / macro on startup

Post by Shmuel » Sat 27 Apr, 2019 14:20

1. Could you show a real-life example where it would be useful?
2. A macro may start with a message box asking the user if he wants to execute that macro so the user can either cancel or continue the execution.

kamil
Posts: 29
Joined: Fri 13 Apr, 2012 19:19
Has thanked: 1 time

Optional auto execution of command / macro on startup

Post by kamil » Sat 27 Apr, 2019 14:25

My system's environment is set via Far's "Environment Manager" plugin.

When Windows starts I want to auto-start a specific command, using that environment.

So basically I want to start Far and from within Far launch that command.

But when I manually start Far later (when the system is already running) I don't want it to auto-start that command anymore.

Shmuel
Posts: 5727
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 21 times
Been thanked: 203 times

Optional auto execution of command / macro on startup

Post by Shmuel » Sat 27 Apr, 2019 14:38

You can add an environment variable for that purpose, e.g. "MySystemStarted".
Your auto-starting macro first checks that variable:
if it is already set then the macro returns, otherwise it sets that variable and runs the plugin command.

kamil
Posts: 29
Joined: Fri 13 Apr, 2012 19:19
Has thanked: 1 time

Optional auto execution of command / macro on startup

Post by kamil » Sat 27 Apr, 2019 14:38

Perhaps there is a way to invoke a specific macro from the command line that starts Far?

Or maybe I can check the command line switches that Far was started with, from inside a lua script?

ccaid
Posts: 845
Joined: Fri 12 Jun, 2009 16:04
Has thanked: 17 times
Been thanked: 5 times

Optional auto execution of command / macro on startup

Post by ccaid » Sat 27 Apr, 2019 14:40

kamil,

Code: Select all

>far /?
..........
 -ma  Do not execute auto run macros.
..........
Фар делают добрые люди

Shmuel
Posts: 5727
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 21 times
Been thanked: 203 times

Optional auto execution of command / macro on startup

Post by Shmuel » Sat 27 Apr, 2019 14:45

kamil wrote:
Sat 27 Apr, 2019 14:38
Perhaps there is a way to invoke a specific macro from the command line that starts Far?
Yes, it is described in Far Help, e.g.: far lua:far.Message"Hello" or far lua:@mypath\myfile.lua

kamil
Posts: 29
Joined: Fri 13 Apr, 2012 19:19
Has thanked: 1 time

Optional auto execution of command / macro on startup

Post by kamil » Sat 27 Apr, 2019 15:04

That's perfect - thank you!

kamil
Posts: 29
Joined: Fri 13 Apr, 2012 19:19
Has thanked: 1 time

Optional auto execution of command / macro on startup

Post by kamil » Sat 27 Apr, 2019 15:06

BTW, I did check in the Command Line switches of Far Help, but it wasn't there.

Shmuel
Posts: 5727
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 21 times
Been thanked: 203 times

Optional auto execution of command / macro on startup

Post by Shmuel » Sat 27 Apr, 2019 15:40

kamil wrote:
Sat 27 Apr, 2019 15:06
I did check in the Command Line switches of Far Help, but it wasn't there.
It is in the last paragraph of that page.

Post Reply

Return to “Support and Troubleshooting”