SEARCH

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

You are not logged in.

#1 2013-04-09 21:49:53

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Adding programs to the "Open With" options

Hello all,

I've got two plain text-editing programs that I use, JDarkRoom and Sublime Text.

http://www.codealchemists.com/jdarkroom/

http://www.sublimetext.com/


I've built shell scripts to allow me to open them more quickly. (Simple ones, basically keeping me from entering a lot of directories as I type.)

The programs run fine, but I'd like to be able to use them when I'm maneuvering around with the mouse, especially with an 'open with' functionality. I'm not sure how to get Crunchbang to recognize the new programs as select-able commands.

Can anyone point me in the right direction for this?


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

Help fund CrunchBang, donate to the project!

#2 2013-04-10 05:03:02

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,843
Website

Re: Adding programs to the "Open With" options

Are you using Thunar to open the files? If so, just go to the "Open with Other Application" right-click option, choose your script (you'll brobably have to enter the command manually at "use a custom command") and click "open". Only check the "Use as default" box if that's what you want. Next time, that choice should appear in the "open with" list. You might have to restart Thunar.


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#3 2013-04-10 18:43:16

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

I tried this... and I can use the custom command to run the script, but it's not opening the text file in the subsequent program.

I'm wondering how I can get Thunar to recognize the installed programs as text-editors in the first place, so it can pass on the 'open file' command to them, the same way it's doing it with Geany, Abiword, Emacs, (and DosBox for some reason).

I'm wondering if maybe the Sublime Text executable just doesn't have a method to pass along a specific file to open?


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#4 2013-04-10 22:19:39

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,121

Re: Adding programs to the "Open With" options

perhaps the secret is in

tail /usr/share/applications/geany.desktop | grep Mime

edit:

example /usr/share/applications/sublime.desktop (modify the Exec path);

[Desktop Entry]
Type=Application
Version=1.0
Name=Sublime
GenericName=Integrated Development Environment
Comment=fast and lightweight
Exec=/home/user/apps/Sublime/sublime_text %F
Icon=sublime
Terminal=false
Categories=GTK;Development;IDE;
MimeType=text/plain;text/x-chdr;text/x-csrc;text/x-c++hdr;text/x-c++src;text/x-java;text/x-dsrc;text/x-pascal;text/x-perl;text/x-python;application/x-php;application/x-httpd-php3;application/x-httpd-php4;application/x-httpd-php5;application/xml;text/html;text/css;text/x-sql;text/x-diff;
StartupNotify=true

logout/login, click around "open with" few times and some magic should happen.

Last edited by brontosaurusrex (2013-04-10 22:53:40)

Offline

#5 2013-04-11 11:36:05

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,843
Website

Re: Adding programs to the "Open With" options

typewriterjason wrote:

I tried this... and I can use the custom command to run the script, but it's not opening the text file in the subsequent program.

I think the problem might be your script - is it passing the file to the editor when it opens it? Thunar will pass the filename as an argument to whatever command you have selected in the "open with" dialogue - your script in this case, which then has to pass it on to the editor. You can collect any arguments that were sent to the script (bash, I'm presuming) in $1, $2.. for the first, second... or "$@" for all the arguments. separately quoted. If for example the last line of your script is ' sublimetext ' then try changing it to ' sublimetext "$@" '. If that doesn't work, can you post the code of the script here?


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#6 2013-04-11 18:12:19

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

That worked, sort of.

It worked through the method of choosing "open with" and then choosing the script file. It opened the new file!

But then clicking on other plain text files doesn't open them in Sublime Text... they just don't open from what I can tell.

My end-goal would be able to get Sublime Text recognized by the system for all plain-text editing, the same way it's recognizing Geany, Emacs and others.

Here's my script, startsublime.sh

(I've made the changes you suggested, John.)

#sublime text startup script

./Programs/Sublime\ Text\ 2/sublime_text "$@"

Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#7 2013-04-11 19:13:23

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,121

Re: Adding programs to the "Open With" options

and my solution is not working cos you are afraid of reptiles or some other reason?

Offline

#8 2013-04-11 20:18:33

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

brontosaurusrex wrote:

and my solution is not working cos you are afraid of reptiles or some other reason?

Ha! Nothing against reptiles!

Haven't had a chance to try it yet. John's option was faster... but I'll try it soon!

Not sure I totally understand it though. You're suggesting adding a file to the applications folder to help in getting Thundar to recognize the program and pass commands to it? Does it matter where Sublime Text is sitting in the hard drive? (Right now I've got it in the 'bin' directory within my user directory)


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#9 2013-04-11 21:49:05

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,121

Re: Adding programs to the "Open With" options

exactly, no it doesn't matter where the sublime bin is, just make the "Exec=" part of that .desktop to point there.

Offline

#10 2013-04-12 04:21:19

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,843
Website

Re: Adding programs to the "Open With" options

If brontosaurusrex's solution with a .desktop file works out you shouldn't need that startup script at all. smile

Last edited by johnraff (2013-04-12 04:22:55)


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#11 2013-04-12 18:03:32

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

That worked! Thanks, bronto!

It looks like if I want to run it in the terminal, I still need the script... but the open with functionality works perfect.

Even though my problem is solved, it does make me wonder. How would I also get terminal functionality at the same level? (Opening a file through sublime in the terminal.) I guess the script sort of does that, but it's a bit kludgy. Do I need to give the program executable special permissions or anything?


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#12 2013-04-12 19:38:06

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,121

Re: Adding programs to the "Open With" options

either,
a. add your sublime directory to PATH
(echo $PATH)
or
b. make alias in .bash_aliases like
alias edit='/some/place/sublime-text'
then just
edit myscript.txt (should open myscript.txt in sublime)

Offline

#13 2013-04-12 19:42:08

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

Heck, I could do both!

I'll do a bit of research on the process for those options and come back when I've tried it!


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#14 2013-04-12 22:40:59

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

I added the sublime text directory to PATH, using this:

PATH=$PATH:/home/etc/etc

That seems to work okay.

But when I added to the .bash_aliases file (I had to make one actually) I'm not finding success.

This is what I get following the 'edit' command. Do I need to log out and in again for bash to recognize the .bash_aliases file?
(the file I'm trying to edit is itself the .bash_aliases file)

Warning: unknown mime-type for ".bash_aliases" -- using "application/octet-stream"
Error: no "edit" mailcap rules found for type "application/octet-stream"

When I use edit on a regular .txt file, I'm not sure what it's opening... but it's not sublime.


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#15 2013-04-13 05:18:56

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,121

Re: Adding programs to the "Open With" options

Defaulf on waldorf is ~/.bash_aliases which starts when bash is invoked via ~/.bashrc
(to restart bash you can use: exec bash -l)

Last edited by brontosaurusrex (2013-04-13 05:24:10)

Offline

#16 2013-04-13 16:25:56

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,843
Website

Re: Adding programs to the "Open With" options

brontosaurusrex wrote:

either,
a. add your sublime directory to PATH
(echo $PATH)
or
b. make alias in .bash_aliases like
alias edit='/some/place/sublime-text'
then just
edit myscript.txt (should open myscript.txt in sublime)

Or, a slight variant on (a), make a symlink from your ~/bin directory (which should be in your PATH) with a name 'sublime-text' pointing to where the executable actually is.


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#17 2013-04-17 05:31:00

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

Hey guys... here's what I'm getting back from bash when I start it up, after creating a .bash_aliases file. (There wasn't one there already.)

bash: .bash_aliases: command not found

Does that mean the command I've got in the bash aliases file is incorrect, or is it that .bash_aliases itself is built wrong? (Maybe both?)

I'll try the symlink idea, John!

I also tried adding the directory to $PATH, but I'm not sure how to get it to stick. Where would I save this for it to automatically be in bash's paths?

(Thanks guys so much for answering all these questions; it's been extremely educational and fun for me!)


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#18 2013-04-17 05:37:23

brontosaurusrex
#! Red Menace
Registered: 2012-06-15
Posts: 1,121

Re: Adding programs to the "Open With" options

what does "cat .bashrc | grep bash_aliases" say?
i get:

# ~/.bash_aliases, instead of adding them here directly.
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

Offline

#19 2013-06-12 21:59:32

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

Apologies for the long time away! Some of my other projects overtook my tech love for a while. But now I'm back!

Bronto, here's what I got from that command; I think it's the same as yours.

# ~/.bash_aliases, instead of adding them here directly.
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

Does this mean that it's not recognizing .bash_aliases as a command, maybe?

bash: .bash_aliases: command not found


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#20 2013-06-13 12:16:30

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,843
Website

Re: Adding programs to the "Open With" options

The . is the command! It's the same as 'source'.  (.bash_aliases is a file.)
So I can't see why your code isn't working... have you got the 'fi' at the end? ie:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#21 2013-06-19 00:41:41

typewriterjason
#! CrunchBanger
Registered: 2011-08-28
Posts: 203

Re: Adding programs to the "Open With" options

Yep, I've got the 'fi' on the end there.

Here's a question... based on the syntax, is it looking for the file in the main user directory, or in root?

Last edited by typewriterjason (2013-06-19 01:42:50)


Fortune favors the bold.
#! WALDORF (just converted)
Asus EEEPC 1001PXD
2GB RAM

Offline

#22 2013-09-04 01:57:17

OragamiOstrich
New Member
From: Oakdale, California
Registered: 2012-10-29
Posts: 5
Website

Re: Adding programs to the "Open With" options

if you can't get your alias to work try

sudo ln -s /Programs/Sublime\ Text\ 2/sublime_text /usr/local/bin/

That'll put a symbolic link (equivalent to a windows shortcut) to it in the PATH


In a world with no walls or fences, who needs Windows or Gates? 
http://gundlach-marketing.com

Offline

#23 2013-09-05 17:03:34

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,843
Website

Re: Adding programs to the "Open With" options

typewriterjason wrote:

Here's a question... based on the syntax, is it looking for the file in the main user directory, or in root?

Sorry I missed your question for 3 months. hmm
~ is shorthand for the user directory. (ie $HOME)


John
--------------------
( a boring Japan blog , idle twitterings  and GitStuff )
#! forum moderator

Offline

#24 2013-09-06 21:16:52

CBizgreat!
#! Die Hard
Registered: 2011-07-27
Posts: 1,476

Re: Adding programs to the "Open With" options

What about thunar custom actions ? Seemed worth mentioning ... Recall there being a thread about the topic somewhere in the crunchville's Tips/tricks section. Well ... no doubt there are several in these forums and gotta be plenty of info about it on the net. If anyone's interested in the topic.

Afterthought babble ...

Sometimes hard to find things even with a site search tool ( though can't hurt using it too.) A perhaps useful tip to find stuff, that I've found useful ... Google advanced search modifiers. ie: site:URL-of-the-website-you-want-to-search keywords you want to search for. In this case, search I used and it did turn up what looked to be some good info. I tried ...

site:http://crunchbang.org/forums/ thunar custom actions

Last edited by CBizgreat! (2013-09-06 21:37:45)


Some common cbiz abbreviations. This will save me time and yet @ same time tell folks what the babble is supposed to mean.

Vll ! = ( Viva la gnu/Linux !)    Vl#!! = ( Viva la #! !)    Last but not least, UD ... OD ! = ( Use Debian ... or die !) tongue

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.

Debian Logo