howto use Puppybasic for small tasks

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

howto use Puppybasic for small tasks

#1 Post by MU »

We sometimes get requests on short code-examples to learn PuppyBasic.
This one is very short, but helpfull.

I often download a dotpup attached to forum-message to upload it on my mirror.

Now it would be nice to add a small HTML-file, that has a link to the original Forum-message, so that you quickly find it when browsing my repository.
So in addition to
example-0.9.5.pup
I need:
example-0.9.5.htm

But I am lazy, so I sometimes I do not add such a HTML-file.

For this reason, I wrote a very small script, to help me.

I can drag the downloaded dotpup on it, and then can enter the URL of the forum-message.
Then the HTML-file is created automatically.
It has only the link, that can be clicked to go to the forum-message.

I think this is a typical task, that in a varied manner you could use too.

So here is the code.
It is so short, that you easily could modify it.

Save it as /root/myscript
Make it executable with this comand in a consolewindow:
chmod 755 /root/myscript

Now drag it from Roxfiler to your desktop.
Now drag a dotpup on this new icon on your desktop to test it.

Mark

Code: Select all

#!/usr/bin/puppybasic

include "/usr/lib/wxbasicscript/basefunctions.inc"


// find out the name of the file dragged on this application
a=argvtostring()

// exit if no file was dragged
if a = "" then
  end
end if

// exit, if it is not a dotpup
if right(a,4) != ".pup" then
  end
end if

// the HTML-file shall have the same name, only with .htm instead of .pup
a=cutright(a,".pup")
htmlfile = a & ".htm"

// here the user can enter the URL of a forum-message
result,choice = xdialog(" --title \"enter URL\" --inputbox \"enter URL for the forum-message presenting\n" & a & "\" 10 50 \"http://www.murga.org/~puppy/viewtopic.php?t=\"")

// exit if not OK was pressed
if result != 0 then
  end
end if

// exit if no message-number was entered
if right(choice,1) = "=" then
  end
end if

// create the final link
theline="<a href=\"" & choice & "\">" & choice & "</a>"

// write it to a HTML-file
writestringtofile( htmlfile , theline)


Post Reply