1

Does awesome window manager set some kind of flag during restart. I've some autostart commands in rc.lua and they are executed every time I restart the window manager.

How can I determine in the rc.lua if the file execution is done because of a restart?

saga
  • 1,933
  • 2
  • 17
  • 44

3 Answers3

2

Awesome v4.x?
Declare a run_once function.
numlockx on as an example

function run_once(cmd)                                                                                                               
  findme = cmd 
  firstspace = cmd:find(" ")
  if firstspace then
    findme = cmd:sub(0, firstspace-1)
  end        
  awful.spawn.with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || (" .. cmd .. ")")
end          

run_once("numlockx on")
ploth
  • 435
  • 8
  • 16
1

Sorry, just want to comment @ploth 's answer...but not enough reputation. The given code is the one on the former wiki, and it didn't work for me. I use this one :

function run_once(cmd)                 
 local findme = "ps x U $USER |grep '" .. cmd .. "' |wc -l"              
 awful.spawn.easy_async_with_shell( findme ,
   function(stdout,stderr,reason,exit_code) 
     if tonumber(stdout) <= 2 then
       awful.spawn( cmd )
     end
   end)
end    
david
  • 1,302
  • 1
  • 10
  • 21
0

Use the included spawn.once function, e.g.

awful.spawn.once("dex --autostart --environment awesome")

https://awesomewm.org/doc/api/libraries/awful.spawn.html#once

Horus
  • 617
  • 7
  • 10