Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 27 Jan 2015, 10:46
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Execute shell script from browser bookmark?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
greengeek

Joined: 20 Jul 2010
Posts: 2834
Location: New Zealand

PostPosted: Thu 08 Jan 2015, 03:20    Post subject:  Execute shell script from browser bookmark?  

I would like to be able to click on a browser bookmark and have it run a shell script rather than linking to a website or to a local directory. From what I read there may be some way to use javascript and/or ajax to achieve this.

Has anyone ever achieved this using any method at all?
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2654
Location: www.eussenheim.de/

PostPosted: Thu 08 Jan 2015, 09:44    Post subject: Execute shell script from browser bookmark?
Subject description: example
 

Do you mean something like this?

EDIT
wait a moment
I will add the script...
Code:
# sourced by /usr/share/doc/*html
#20141107 2>/dev/null added
#20141113 other translations tested on translated title and counted
#20141115 output p which counts and lists translations and refers to original

echo "Content-type: text/html;charset=UTF-8"
echo

alias _=gettext

[ "${QUERY_STRING%%=*}" = "LANGUAGE" ] && LANGUAGE=${QUERY_STRING#*=} && LANGUAGE=${LANGUAGE%%&*}
[ "$LANGUAGE" ] || LANGUAGE=${LANG%%_*} # enable languages other than actual one

#p="$p $(_ fatdoghelp 'Translations: ')";for L in `ls /usr/share/locale/*/LC_MESSAGES/${TEXTDOMAIN}.mo|cut -d/ -f5`;do a1='<a href="?LANGUAGE='$L'">';a2='</a>'; [ "$L" = "$LANGUAGE" ] && { a1=;a2=; } ;p="$p ${a1}${L}${a2} ";done

# indicate (and link) original and translations

#compare title and translated title
TITLE="`grep -m 1 '<title>' $0`" #ex: <title>$(_ "Tray Icons")</title>
TITLE="${TITLE%\"*}"             #ex:<title>$(_ "Tray Icons
TITLE="${TITLE##*\"}"            #ex:Tray Icons
num=0 # number of translations

for L in `ls /usr/share/locale/*/LC_MESSAGES/${TEXTDOMAIN}.mo 2>/dev/null|cut -d/ -f5`; do

 LL=$LANGUAGE
 LANGUAGE=$L; TTITLE="`gettext \"$TITLE\"`"
 LANGUAGE=$LL
 [ "$TITLE" = "$TTITLE" ] && continue
 #translated title is different
 
 num=$((num + 1))
 a1='<a href="?LANGUAGE='$L'">'
 a2='</a>'
 [ "$L" = "$LANGUAGE" ] && { a1=; a2=; }
 
 #find language name
 if [ -f /usr/share/i18n/lang_names ]; then
  LN="`grep "^${L}:" /usr/share/i18n/lang_names`"
  [ $LN ] && LN=${LN##*:}
 
 elif [ -d /var/cache/fatdog-choose-locale.sh ]; then
  LN="`grep -m1 "^lang_name " /var/cache/fatdog-choose-locale.sh/locales/${L}* | head -n1`"
  LN=${LN##* }
  LN=${LN//\"/}
 
 else
  # use code from fatdog-choose-locale.sh
  :
 fi
 [ $LN ] || LN=$L # fallback

 t="$t ${a1}${LN}${a2} "
done

# now the output p which counts and lists translations and refers to original
# use gettext argument 'fatdoghelp' just in case there will be another TEXTDOMAIN
[ "$LANGUAGE" != "en" ] && p="$(_ fatdoghelp 'Original: ') <a href=\"?LANGUAGE=en\">$(_ fatdoghelp 'English')</a><br>"
p="$p `eval echo $(ngettext fatdoghelp "There is just 1 Translation: " "There are $num Translations: " $num)` $t"
[ $num -eq 0 ] && unset p
shell_script_bookmarked_in_browser.png
 Description   
 Filesize   50.34 KB
 Viewed   138 Time(s)

shell_script_bookmarked_in_browser.png

Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2834
Location: New Zealand

PostPosted: Thu 08 Jan 2015, 12:40    Post subject:  

Hi L18L - thank you for the example. If I interpret it correctly it appears to me that your bookmark runs a script that changes the translation of a locally sourced html page, is that correct?

What I don't understand is how the bookmark passes control to the script?
The script says it is "# sourced by /usr/share/doc/*html " but how does that html code transfer control to the script (which I assume is bash?)

Also - the script is probably limited to operating only on the contents of the current page - I am keen to find a method of triggering an external script that is completely separate to the current page. Do you think that may be possible?

Example: I would like to have a bookmark that opens something like Abiword (ie: a completely separate programme external to the browser, and not sharing or transferring any data with the current page).

I think Google Chrome used to have an 'npapi' interface to achieve this but it is apparently going to be deprecated soon - maybe there are security concerns with allowing such a function? If possible I would like to do this from Firefox rather than Chrome.

Many thanks for any ideas!
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2654
Location: www.eussenheim.de/

PostPosted: Thu 08 Jan 2015, 14:48    Post subject:  

greengeek wrote:
Hi L18L - thank you for the example. If I interpret it correctly it appears to me that your bookmark runs a script that changes the translation of a locally sourced html page, is that correct?
Correct. Bookmarked just for your question. It might become Fatdog's help system

greengeek wrote:
What I don't understand is how the bookmark passes control to the script?
The script says it is "# sourced by /usr/share/doc/*html " but how does that html code transfer control to the script (which I assume is bash?)
I did not reveal everything. Web server mongoose is running with cgi pattern=html and cgi _interpreter= /bin/sh. I have been using php some years but here in Puppy/Fatdog shell should do it.

greengeek wrote:
Also - the script is probably limited to operating only on the contents of the current page - I am keen to find a method of triggering an external script that is completely separate to the current page. Do you think that may be possible?
No. A browser is a browser and no application launcher.
I have been trying:
console commands can be executed.
htop. mc, ... can be launched
abiword and others return:
Code:
No DISPLAY: this may not be what you want.


greengeek wrote:
Example: I would like to have a bookmark that opens something like Abiword (ie: a completely separate programme external to the browser, and not sharing or transferring any data with the current page).
Fatdog64's QuickApps might be what you are searching for.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4454

PostPosted: Thu 08 Jan 2015, 21:47    Post subject:  

Yes. You can associate an extension with any program. I used a .pidgin extension and associated it with pidgin.
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0692s ][ Queries: 12 (0.0098s) ][ GZIP on ]