SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2014-10-11 15:37:56

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

[SOLVED]Bash and xdotool question

I've scripted a batch-process to copy and resize a load of icon images, and convert some to svg, using inkscape. The problem is that inkscape opens a dialog for each file to choose whether to link or embed it (this can't be bypassed afaik, which has been a dev request for at least 4 years), so I have to keep pressing Return until they are all closed.

I have worked out how to use xdotool to close the dialog, but that needs to be run from another terminal.

So how to script it to run from the same shell script?

The command to loop through the images and convert to svg:

for i in scalable/*.png; do 
    inkscape -f "$i" -l "${i%.png}.svg";
done

The command to find the dialog window and send the "Return" keypress:

xdotool key --window "$(xdotool search --class inkscape | head -n 2 | tail -1)" Return

Putting the xdotool command after the inkscape command, inside the for loop has no effect. With my limited bash knowledge it would seem that the inkscape process has to complete before the xdotool command can run (if they are run in the same shell), which then makes it pointless.

I've spent far longer on this than just pressing "OK" would have been!

Last edited by damo (2014-10-11 20:20:19)


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

Be excellent to each other!

#2 2014-10-11 15:45:23

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2012-03-22
Posts: 1,026
Website

Re: [SOLVED]Bash and xdotool question

An idea: you can try to use imagemagick:

$ convert image.png image.svg

Of, course, you may need to add some options ...

(I wonder if the quality will satisfy you ...)


Postpone all your duties; if you die, you won't have to do them ..
--> The very new BL forum! <--

Offline

#3 2014-10-11 15:58:11

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: [SOLVED]Bash and xdotool question

iMBeCil wrote:

An idea: you can try to use imagemagick:

$ convert image.png image.svg

Of, course, you may need to add some options ...

(I wonder if the quality will satisfy you ...)

No, that just embeds the raster image and changes the filetype, it doesn't create a scalable vector image. An alternative is Potrace, but that only does B&W. (And I haven't tried Autotrace yet)


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#4 2014-10-11 16:16:35

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2012-03-22
Posts: 1,026
Website

Re: [SOLVED]Bash and xdotool question

OK, I must have misunderstood what you want.

As a side note: damo, you are almost certainly much more knowledgeable in graphics than me ... but somehow I do not see any difference between

$ inkscape -f image.png -l image.svg

and

$ convert image.png image.svg

I tried this on some random PNG image, and apart from the different SVG file size, the 'inkscape' version does nothing less and nothing more than 'convert'. AFAIK.


Postpone all your duties; if you die, you won't have to do them ..
--> The very new BL forum! <--

Offline

#5 2014-10-11 16:20:41

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2012-03-22
Posts: 1,026
Website

Re: [SOLVED]Bash and xdotool question

Back to original question:

damo wrote:

The command to loop through the images and convert to svg:

for i in scalable/*.png; do 
    inkscape -f "$i" -l "${i%.png}.svg";
done

The command to find the dialog window and send the "Return" keypress:

xdotool key --window "$(xdotool search --class inkscape | head -n 2 | tail -1)" Return

Putting the xdotool command after the inkscape command, inside the for loop has no effect. With my limited bash knowledge it would seem that the inkscape process has to complete before the xdotool command can run (if they are run in the same shell), which then makes it pointless.

Then, you can put some waiting time between 'inkscape' and 'xdotool':

for i in scalable/*.png; do 
    inkscape -f "$i" -l "${i%.png}.svg"
    sleep 0.8
    xdotool key --window "$(xdotool search --class inkscape | head -n 2 | tail -1)" Return
done

(Or something like this.) Experiment with various 'sleep' times.


Postpone all your duties; if you die, you won't have to do them ..
--> The very new BL forum! <--

Offline

#6 2014-10-11 17:02:27

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: [SOLVED]Bash and xdotool question

From Imagemagick documentation:
"If the "AutoTrace" library is not installed and compiled into IM, then the SVG output generated will be a huge number of single pixel circles, generating a binary result, rather than a smooth SVG outlined image. Such images are huge by comparision, and often take a very long time to render by SVG render."

So it seems that using "convert" doesn't generate a true vector image.

But to get back to the bash - using a sleep command doesn't work, although I did try it anyway. The "inkscape" command doesn't complete until it gets some input from the dialog box, so every command after that is waiting.


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#7 2014-10-11 17:35:49

porkpiehat
#! Die Hard
Registered: 2012-10-02
Posts: 1,007

Re: [SOLVED]Bash and xdotool question

Just some random ideas. I don't know if any of this will work, as I don't use inkscape.

1. What if you put the xdotool call *before* the inkscape call, and background it waiting and sleeping, like this:

(sleep 1s && xdotool <options>) &
inkscape <options>

Then the xdotool call should be waiting in the background, and will run after the sleep even if inkscape is still open.

2. What if you background the inkscape call?

inkscape <options> &
xdotool <options>

Then the xdotool call should run immediately after inkscape opens (it won't wait, because inkscape is backgrounded). You may need to add some sleep before the xdotool call.

3. Can you do the same thing with wmctrl? That might be a more graceful solution, but you may still have some timing issues.

Last edited by porkpiehat (2014-10-11 17:37:25)

Offline

#8 2014-10-11 17:39:56

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2012-03-22
Posts: 1,026
Website

Re: [SOLVED]Bash and xdotool question

damo wrote:

From Imagemagick documentation:
"If the "AutoTrace" library is not installed and compiled into IM, then the SVG output generated will be a huge number of single pixel circles, generating a binary result, rather than a smooth SVG outlined image. Such images are huge by comparision, and often take a very long time to render by SVG render."

So it seems that using "convert" doesn't generate a true vector image.

Thanks a lot for reading documentation instead of me smile I mean it smile

damo wrote:

But to get back to the bash - using a sleep command doesn't work, although I did try it anyway. The "inkscape" command doesn't complete until it gets some input from the dialog box, so every command after that is waiting.

I just tested it, and this works (note '&' at the end of 'inkscape' command):

for i in scalable/*.png; do 
    inkscape -f "$i" -l "${i%.png}.svg" &
    sleep 0.8
    xdotool key --window "$(xdotool search --class inkscape | head -n 2 | tail -1)" Return
done

The solution is probably sub-optimal and dirty, but it does work.

I have to leave computer right now, so cannot test it, but better solution would be if you after 'inkscape ... &' - instead of 'sleep' - wait for Link/Embedded to show up, and then execute 'xdotool'.

EDIT: porkpiehat was faster.

Last edited by iMBeCil (2014-10-11 17:43:21)


Postpone all your duties; if you die, you won't have to do them ..
--> The very new BL forum! <--

Offline

#9 2014-10-11 18:14:30

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: [SOLVED]Bash and xdotool question

Thanks guys, I actually got there in the end, while you were posting!
I had tried the "&" to start a new process, but the xdotool Return wasn't doing anything. It worked if I did one command at a time in the terminal, so adding "&" and "sleep" has worked in the for-loop.

for i in scalable/*.png; do 
    inkscape -f "$i" -l "${i%.png}.svg" &
    sleep 0.4
    xdotool key --window "$(xdotool search --class inkscape | head -n 2| tail -1 )" Return
done

0.4s was as quick as I could get it to work sad 

It seems a dirty hack - I'm sure there is a more elegant way of scripting it. Thanks again for taking the time to help smile


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

#10 2014-10-11 19:38:32

iMBeCil
WAAAT?
From: Edrychwch o'ch cwmpas
Registered: 2012-03-22
Posts: 1,026
Website

Re: [SOLVED]Bash and xdotool question

No problem damo, I'm glad you solved your problem.


Postpone all your duties; if you die, you won't have to do them ..
--> The very new BL forum! <--

Offline

#11 2014-10-11 20:26:56

Joe90
#! Junkie
Registered: 2013-10-10
Posts: 337

Re: [SOLVED]Bash and xdotool question

I know you have sorted your problem, but resolving the embed/link box is available in unstable releases of Inkscape +0.48 as an option in Preferences/Bitmaps

Last edited by Joe90 (2014-10-11 20:27:08)

Offline

#12 2014-10-11 20:49:15

damo
#! gimpbanger
From: N51.5 W002.8 (mostly)
Registered: 2011-11-24
Posts: 5,434

Re: [SOLVED]Bash and xdotool question

@Joe90

Great, thanks for that. Jessie has 0.48.5-2, which is what I'm running on this machine. I'll check it out on my sid box (0.48.5-3)

I wouldn't have thought of looking in Prefs/Bitmaps though - I checked Prefs/Import-Export sad


BunsenLabs Group on deviantArt
damo's gallery on deviantArt
Openbox themes
Forum Moderator smile

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: acrobat

Debian Logo