Joined: Sep. 2005
||Posted: Nov. 16 2007,01:17
My first lua program.
It tries to align the icons on a grid (without re-arranging).
I can more or less align the icons, but don't know how to restart dfm
without quiting X. Does anyone know the commands to do this ?
I also need how to call system commands to move the files around.
There's also the problem that not only does it re-align the desktop
icons, but also any other it sees. Can't seem to find a way to
distinguish the desktop-only paths. Comments appreciated, or
even if anyone has a more efficient way of doing this.
|Code Sample |
x_align = 48
y_align = 64
x_mid = math.floor(x_align/2);
y_mid = math.floor(y_align/2);
fin = assert(io.open("unzipped.dfminfo", "r"))
fout = assert(io.open("modified.dfminfo", "w"))
count = 1
while true do
line = fin:read()
if line == nil then break end
pattern = "_POS"
i= string.find (line, pattern)
if i then -- if possible candidate
s = string.sub(line, i+6)
from,till,x,y = string.find (s, "%s*(%d+)%s*(%d+)")
if (x and y) then -- if candidate
io.write (count," : ", x, ",", y,"\n")
mod = math.mod (x, x_align)
x = x - mod
if mod > x_mid then
x = x + x_align;
mod = math.mod (y, y_align)
y = y - mod
if mod > y_mid then
y = y + y_align;
s=string.sub (line, 1, i+5) -- the start of the line
fout:write (s,x," ",y, "\n") -- the modification
fout:write (line, "\n") -- unaltered candidate
count = count + 1
fout:write (line, "\n") -- unaltered non-candidate
io.write (string.format("%6d ", count), "\n")