You are not logged in.

#1 2016-04-06 16:59:35

andoru
New Member
Registered: 2016-04-06
Posts: 3

Execute files with sh scripts from context menu

So I made two shell scripts under /usr/bin/ (would've preferred under ~/bin, but I couldn't get it to add that folder to the path, even when appending it to ~/.bash_profile), named 'Wine' and 'Wine64', each containing something like this:

#!/bin/bash 

FILE1=$1
WINEARCH=win64 WINEPREFIX=/home/##/.wine64/ /usr/bin/wine64 $FILE1

So basically it's a script to automate the switching between wine architectures and to set the proper prefix path. While this works fine when launching an application from a terminal, say:

$ Wine64 some-windows64-app.exe

I can't get it to work when right clicking the said executable, and opening it with Wine64 (which I previously added it as a choice in the context menu)
So is there something I'm doing wrong, or is this not possible at all?
In the latter case, is there any way to achieve this through other means?

I'm doing it this way as I'm installing this system for a relative that isn't that knowledgeable with Linux (so I would like to avoid instructing them how to launch commands in a terminal), but would still like to offer him a Windows compatibility layer for the odd Windows-only app that he might need.

Offline

#2 2016-04-06 17:31:11

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: Execute files with sh scripts from context menu

andoru wrote:

So I made two shell scripts under /usr/bin/ (would've preferred under ~/bin, but I couldn't get it to add that folder to the path, even when appending it to ~/.bash_profile....

Are you using a stock BL install? `$HOME/bin` (not "~/bin") should be in your $PATH already - here is mine for example:

[damo@debian ~]$ echo $PATH
/home/damo/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#3 2016-04-06 17:43:23

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Execute files with sh scripts from context menu

andoru wrote:

So I made two shell scripts under /usr/bin/ (would've preferred under ~/bin, but I couldn't get it to add that folder to the path, even when appending it to ~/.bash_profile)

first of all you should fix this.

#!/bin/bash 

FILE1=$1
WINEARCH=win64 WINEPREFIX=/home/##/.wine64/ /usr/bin/wine64 $FILE1

is that the actual script?
why aren't the commands on seperate lines?

I can't get it to work when right clicking the said executable, and opening it with Wine64 (which I previously added it as a choice in the context menu)

i guess thunar passes files differently to the script, so your $1 is not what you think it is.
have you tried to add a debug line like

echo "$1" > $HOME/debugmyscript

...and yes, you should always put quotes around variables. maybe that in itself will fix your problem.

Offline

#4 2016-04-06 17:43:29

andoru
New Member
Registered: 2016-04-06
Posts: 3

Re: Execute files with sh scripts from context menu

I'm using Debian Sid with Cinnamon, hence me asking in this subforum tongue

All I get is this:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

And in ~/.profile:

$ cat .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

Yet, it still refuses to add that directory to the path. I also tried removing the "if" and "then" clauses, but still the same...

Regardless this issue, the scripts do turn up in the terminal as commands while the shell scripts are in /usr/bin/, but I can't get them to work from the context menu in Nemo/Thunar/Nautilus/whatever.

Last edited by andoru (2016-04-06 17:47:17)

Offline

#5 2016-04-06 18:27:46

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: Execute files with sh scripts from context menu

In thunar for example, what do you have for the context menu item? IIRC it should be something like 
"<executable> %f"


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#6 2016-04-06 19:07:32

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: Execute files with sh scripts from context menu

Try not using the tilda, and write out your home path completely, so try it like:

/home/<yourname>/bin   

instead of using the tilda shortcut


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#7 2016-04-06 19:12:32

Horizon_Brave
Operating System: Linux-Nettrix
Registered: 2015-10-18
Posts: 1,473

Re: Execute files with sh scripts from context menu

Also, try playing around with the $x variables. Perhaps another value is being passed to $1 before it reads in the target program. Try some echo tests to see what is being called  in $1 when you run it from Thurnar


"I have not failed, I have found 10,000 ways that will not work" -Edison

Offline

#8 2016-04-06 19:17:23

andoru
New Member
Registered: 2016-04-06
Posts: 3

Re: Execute files with sh scripts from context menu

ohnonot wrote:

...and yes, you should always put quotes around variables. maybe that in itself will fix your problem.

Yeah... so as you noticed, I'm not very good with bash scripts yet tongue

Is this correct?

#!/bin/bash

FILE1="$1"
WINEARCH=win32 WINEPREFIX=/home/frank/.wine/ 
/usr/bin/wine "$FILE1"

But I think I didn't make it clear enough, I meant that I can't get it to launch when typing (for example) Wine64 in the custom command in the "Open With" window:


cj0ElRY.png

Above, the middle button, "Als Vorgabe festlegen" (Set as default) and OK should've been clickable.

Offline

#9 2016-04-06 21:00:43

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: Execute files with sh scripts from context menu

Your script is expecting a parameter to be passed to it, so it seems that typing just "Wine64" may not be sufficient.

BTW you don't need

FILE1="$1"

You can just use

/usr/bin/wine "$1"

And to be the safe side, I would put each variable assignment on separate lines.

As @H_B said, try echoing variables to see if what you get is what you were expecting. For example, add these after the var assignment lines

echo "$0" > ~/tempfile    # name of shell or script
echo "$1" >> ~/tempfile   # first parameter passed to script
echo "$WINEARCH" >> ~/tempfile
echo "$WINEPREFIX" >> ~/tempfile

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#10 2016-04-07 00:46:18

tknomanzr
BL Die Hard
From: Around the Bend
Registered: 2015-09-29
Posts: 1,057

Re: Execute files with sh scripts from context menu

You would need to run the executable as damo pointed out in order to pass the file parameter into the script:

 
WINE64 %f

Offline

#11 2016-04-08 20:47:25

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Execute files with sh scripts from context menu

andoru wrote:

And in ~/.profile:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi

Yet, it still refuses to add that directory to the path.

maybe your install does not parse ~/.profile after login.
this is specific to how you log in, so most likely the cinnamon display/login manager holds the answer.


as to your actual problem; well it has been pointed out already, you have to add debug stuff to the script and see what it actually does when called from the filemanager, and you also have to familiarize yourself with how your filemanager handles custom actions.

obviously the scripts are executable, and user permissions are ok, and the same for the directories in question?

sorry i can't be more specific, sid/cinnamon really isn't my world.

Offline

#12 2016-04-09 02:46:09

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,668
Website

Re: Execute files with sh scripts from context menu

LightDm ignores .profile! You need to put the code in ~/.xsessionrc
(But BunsenLabs already has that by default.)

Last edited by johnraff (2016-04-09 02:46:47)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Online

Board footer

Powered by FluxBB