Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sh: 1: cannot open /tmp/shluainput: No such file #12

Open
winterwolf opened this issue Jan 28, 2021 · 2 comments
Open

sh: 1: cannot open /tmp/shluainput: No such file #12

winterwolf opened this issue Jan 28, 2021 · 2 comments

Comments

@winterwolf
Copy link

winterwolf commented Jan 28, 2021

I made a simple color picker for Linux. It is written in Lua but uses Python to get the pixel color. Sometimes it displays some strange messages. They don't break the script, but I just don't want to see them. Looks like there are problems with luash temp files ...

getpixelcolor.py

#!/bin/python3

import gi
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk
import sys

def PixelAt(x, y):
  w = Gdk.get_default_root_window()
  pb = Gdk.pixbuf_get_from_window(w, x, y, 1, 1)
  return pb.get_pixels()

print(tuple(PixelAt(int(sys.argv[1]), int(sys.argv[2]))))

colorpicker.lua

#!/bin/luajit

local luash = require "sh"
local socket = require "socket"
local lume = require "lume" -- luarocks install lume

local getlocation = luash.command("xdotool getmouselocation")
local getcolor = luash.command("./getpixelcolor.py")

while true do
  socket.sleep(0.1)
  local location = tostring(getlocation())
  local array = lume.split(location)
  if not array[1] or not array[2] then goto continue end
  local x = lume.split(array[1], ":")[2]
  local y = lume.split(array[2], ":")[2]
  local color = tostring(getcolor(x, y))
  if not color then goto continue end
  print(x, y, color)
  ::continue::
end

output

271     186     (31, 31, 31)
389     189     (205, 136, 46)
542     448     (38, 38, 38)
503     746     (38, 38, 38)
sh: 1: cannot open /tmp/shluainput: No such file
478     743
477     742     (38, 38, 38)
419     728     (38, 38, 38)
414     716     (38, 38, 38)
469     712     (38, 38, 38)
475     710     (38, 38, 38)
sh: 1: cannot open /tmp/shluainput: No such file
474     704
278     534     (215, 163, 100)
46      550     (15, 15, 15)
91      637     (38, 38, 38)
82      591     (203, 215, 163)
@JBlaschke
Copy link

@winterwolf I have a PR #15 which contains general improvements, and a rewrite of the command execution part. The upside is that you don't need the temporary file, the downside is that luaposix needs to be installed. At least on all the systems that I work with, lua and luaposix are installed.

@JBlaschke
Copy link

By the way -- when you see those errors are you running sh.command in rapid succession? If so, then this might be because of FS latency. If you don't want to use the posix approach, then replacing /tmp/shluainput with os.tmpname() should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants