In i3wm how can I open programs on another workspace at startup? - i3

I've tried multiple ways in my config file to get chromium to open on $ws2 but it just keeps opening on $ws1 on startup.

First you have to find the WM_CLASS(STRING) from xprop. Open xprop and click on the target window you'll see the information about that window. Find WM_CLASS(STRING) second string(for i3wm) then goto the config file of i3 wm .config/i3/config and define the rule like this for_window [class="Chromium"] move to workspace $ws2 for_window [class="TelegramDesktop"] move to workspace $ws3
Here replace the class="String" with the string we found before with xprop.
Alternatively, follow the instructions in section 4.17 of the i3 User’s Guide and insert into your config file an assign declaration e.g. assign [class="Chromium"] $ws2. This will open the program directly on the specified workspace. For less well behaved programs like Spotify the for_window ... move to workspace ... method is required to move the program after it has opened, however.

To open a PROGRAM (chromium in your case) on a particular workspace during startup and return to your first workspace:
1: Add the following to your ~/.config/i3/config file.
exec --no-startup-id i3-msg 'workspace $ws2; exec PROGRAM; workspace $ws1'
1a: Substitute the name of the workspace you want to use for '$ws2' in the example.
1b: Substitute the name of the program to run(execute) with any options for PROGRAM. No quotes are needed for this section
1c: Substitute the name of the workspace you want to return to for '$ws1' in the example, or leave off "; workspace $ws1" to land in $ws2.
1d: Ensure you have the single quote mark where I included them in the example
2: Save the edit (I leave the editor open in case I have to change the file back after restart in place)
3: To test:
3a: Have i3 reread the config file (mod4+shift+c on my system)
3b: Restart i3 in place (mod4+shift+r on my system)
Note: I use $ws1 $ws2 etc in my config because once those are configured it made it easier for me to change titles and awesome icons in just one place vs many places. Method shamelessly stolen from i3 and others as is all of my linux knowledge. :-)

Related

Is there a way to set a python script as program to open a type of file?

The problem:
I'm currently working on a programming language, which uses a simple python interpreter. The interpreter loops over every line with a bunch of if-statements.
The file extension I'd like to use is .ccp.
So far my progress. I want the computer to recognise .ccp files as a CalcScript file, and open it with the script.
I don't want to have a default filename which I can open using text = open("filename.idk","r").read(), I want to open a file like a 'normal' file. You double-click on the file in explorer, and it opens it in the python script. Regardless of the filename.
What I've tried:
Tinkering with the default applications in settings
Tinkering in regedit
Converting my .py file to .exe
Scouering the internet
My code:
https://github.com/AnonymousPixel/CalcScript
Sorry for bad English if there was any.
Summarizing my comments on the question, you can follow the steps below to achieve what you are asking:
Use sys.argv to access the command line arguments. For example the following script will just print all the arguments given to it:
import sys
print("Given arguments: ", str(sys.argv))
Let's name it myprogram.py.
You can then call it (I think) with: python myprogram.py arg1 arg2 arg3 and it will run and print the command line arguments.
Notice that the first argument (sys.argv[0]) is the script's path. So arg1 would be sys.argv[1], arg2 would be sys.argv[2] and so on.
I am saying to use sys.argv because as far as I remember double clicking a file with an extension which has a default opening program, will open that program with the file path as an argument.
Next step is to package your python script to an executable. This has been already asked and answered for example here (which is a duplicate, where you can follow the question which came before it to see even more examples). I used PyInstaller to test it (and on Windows OS). My command was like:
pyinstaller myprogram.py
... and it generated some folders and files. Specifically the folder dist\myprogram contained the executable along with its dependencies. You can then run your program by double clicking on it in the dist\myprogram folder. It should pop a CLI window, printing the arguments (ie only the program's path, since we called it without any other) and immediately exit. Or you can open a CLI window and run it with a command like:
myprogram argument1 argument2 argumentN
(supposing your current working directory is dist\myprogram) and it will indeed print the arguments.
Finally you have to set it up as the program which by default opens files with .ccp extension. On Windows 10, you can do this via:
Open up File Explorer.
Find a file with .ccp extension (or create one).
Right click on it.
Click on Properties on the dialog that pops up.
Go to General tab (if you are not already there) on the dialog that pops up.
On the Open with: section there is a button which reads Change. Click it.
Select More apps at the bottom of the dialog.
Make sure you have the Always use this app to open .ccp files checkbox selected.
Scroll to the bottom of the dialog and click on the blue text which prompts for manually selecting the default app, which in turn pops up a file chooser. I am not running on English language so it is a bit difficult to translate it exactly (I followed some online pages to actually see the default translation for the previous steps).
Select your executable as the default.
Confirm your choices by selecting Ok, Apply or anything else required.
Then you will also be able I think to change this extention later via:
Settings --> Apps --> Default Apps --> Choose default apps by file type.
Some references:
PyInstaller website and introductory manual.
Official page for step 3.
Unofficial page for step 3, a lot more detailed.

How can I open a work space from the command line in i3?

I'd like to script opening a workspace with the 'next' available number and then have open in that workspace maybe a two windows each already pointed at a specific view. Any pointers on how to do that? Is i3 actually scriptable in this regard? I have only just started using i3 and loving it, just want to now have it do things I need on a regular basis ;-)
All of i3's "scripting" that isn't already in the config is done through i3-msg
i3-msg sends messages to i3 window manager. It's mostly config lines(or IPC, which is a bit harder).
How can I open a work space from the command line in i3
How do you open it in your config?
bindsym Mod4+1 workspace $ws1
Something like that right? Now, using i3-msg to move to workspace 1:
i3-msg workspace 1
Simple, right?
The rest of your question is pretty unclear, but I'll do my best:
I'd like to script opening a workspace with the "next" available number"
How you'll start out with doing that is(after doing man i3-msg):
i3-msg -t get_workspaces
This returns a json(if you've done any coding you'll feel warm inside and if not you're going to be scared by the output). Then I'm going to ask you to read up on this:
https://i3wm.org/docs/ipc.html#_receiving_replies_from_i3
Using jq or something like json.sh to parse through the output with bash, you should get which workspaces are "active", example:
[{"num":3,"name":"3","visible":true,"focused":false,"rect":{"x":0,"y":0,"width":1920,"height":1080},"output":"HDMI-1","urgent":false},{"num":2,"name":"2","visible":true,"focused":false,"rect":{"x":3520,"y":0,"width":1920,"height":1080},"output":"VGA-1","urgent":false},{"num":1,"name":"1","visible":true,"focused":true,"rect":{"x":1920,"y":32,"width":1600,"height":868},"output":"eDP-1","urgent":false},{"num":5,"name":"5","visible":false,"focused":false,"rect":{"x":1920,"y":32,"width":1600,"height":868},"output":"eDP-1","urgent":false}]
Reading through the website I gave you, you can see, workspaces 1,2,3 and 5 are "active" aka have windows in them. After parsing the actual json you'll end up with an array or something of this. If you want to spawn on 4(the real "next" desktop) or 6 (aka biggest number + 1) is up to you. You didn't mention what you want to script it in, so I'll leave that to you to figure out.
maybe two windows each already pointed at a specific view
I'm not sure what you mean. You probably want 2 windows of X(we'll use a terminal in this case) in the workspace we've determined as "next" ?
Let's go back to i3-msg for a bit.
Imagine you doing whatever you're trying to do, manually, as a list of commands you're firing to i3.
"Go to workspace X" : i3-msg workspace 4
"Spawn a program called kitty there": kitty
"Split vertically and spawn another program": i3-msg split v
"Spawn another kitty window": kitty
After that you can get back to your current workspace(I suggest saving it in a variable and just reusing i3-msg workspace $curr_workspace).
As I said, the question wasn't about the actual scripting so I left that out to figure it out on your own, but don't hesitate to ask a concrete question under the bash tag. :). Hopefully I didn't completely misunderstand your question.
Welcome to the i3 community.
#Nephilim's post is excellent. Just to add a trick to the toolbox...
Sometimes you might want to script some action relative to a particular window. Like:
Give me a test environment next to this browser.
You can get the window ID by running xwininfo and clicking the window that you want to anchor your automation to. The window ID can be used as a parameter to i3-msg.
For example, running the command below will let you select a window and then will set that window's width to 1000:
i3-msg "[id=$(
xwininfo \
| sed -n 's/.*Window id: \(0x[0-9a-f]*\).*/\1/p'
)] resize set 1000"

How can I enter text into Launchy and append it to the end of a text file?

I'm a Debian Stretch user coming from Windows. In Windows with the launchy app (also available for Linux), I had a method of entering text into launchy that was then appended to the end of a .txt or .md file.
To do this in Windows, I created a file called note.bat that contained the following:
echo %*>>"C:\collectednotes.md"
I'd make launchy aware of note.bat by adding its containing folder to “Launchy” → “Settings” → “Catalog” and adding filetype *.bat.
From there, I'd launch launchy, type note, hit Tab, enter some text, hit Enter, and then the text would be added to the end of collectednotes.md.
A mostly working process is detailed in my answer below. I'll give the green checkmark answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup detailed below) to appropriately handle all special characters.
This may contain the solution to this question:
Which characters need to be escaped in Bash? How do we know it?
Solved (almost). I'm keeping this question unanswered and will give to whoever completes the remaining ~5%. Steps to get the 95% solution with xfce4-terminal version 0.8.3-1:
Install launchy and launchy-plugins (both are version 2.5-4 for me):
apt-get install launchy
apt-get install launchy-plugins
Open terminal to default location of ~/ and create collectednotes.md:
echo "# Launchy Notes Collected Here" > collectednotes.md
Create note.sh shell script:
echo '#!/bin/sh' > note.sh
Create shell script line 2:
echo ALL_ARGUMENTS='"$#"' >> note.sh
Create shell script line 3:
echo 'echo "$ALL_ARGUMENTS" >> ~/collectednotes.md' >> note.sh
If you open note.sh, it will look like:
#!/bin/sh
ALL_ARGUMENTS="$#"
echo "$ALL_ARGUMENTS" >> ~/collectednotes.md
Make note.sh executable:
chmod +x note.sh
Launch launchy and click the gear icon in upper right for settings. If consistency with launchy for Windows is desired, set launchy Hotkey to Alt+Space. If you receive a keyboard shortcut conflict message as I do on Debian with Xfce, first go to Settings, Window Manager, Keyboard tab, and clear Alt+Space as the shortcut for Window operations menu.
Next in launchy settings, go to Plugins tab and enable the plugin Runner. Click the + button and create a new Runner custom command as follows:
- Name: note
- Program: /home/YOURUSERNAMEHERE/note.sh (launchy does not like Program path of ~/note.sh, so a specific path with username is required)
- Arguments: '$$'
Click the Catalog tab and hit Rescan Catalog just in case. Hit OK to close launchy settings.
Now let's test it.
- launch launchy with Alt+Space or your hotkey
- type note (You may have to wait 10 second or so on first run. You'll know things are as expected when you see the text "note" with a orange/yellow icon containing silhouette of a person.)
- hit Tab
- enter some text (no need for single or double quotes or escapes), e.g.: Remember to donate at least $3 to Josh at Launchy https://www.launchy.net/donate.php
- hit Enter
Now open collectednotes.md to confirm the text was captured.
The remaining issues seem to be dealing with single quotes and double quotes. For example, consider the following note:
I don't know what I'd do without Launchy.
Which results in the following in collectednotes.md:
I dont know what Id do without Launchy.
Or:
Would David Allen like universal text capture from anywhere in Linux? My bet is "yes!"
Results in the following in collectednotes.md:
Would David Allen like universal text capture from anywhere in Linux? My bet is \yes!\
Single quoting and/or double quoting the input to launchy doesn't solve it. Note the launchy Runner custom plugin construction component of '$$' is a piece of this puzzle.
I'll give the answer to anyone that can adjust this process (via note.sh and/or launchy plugin setup) to appropriately handle all special characters. Maybe this would add proper escapes to user input with something like gsub.
The rationale for being exacting regarding proper character handling is that this process is useful for copying and logging random chunks of text from web pages, but if common characters like single quotes are not handled as expected, confidence in the system is much reduced.

How to avoid .bzr.log (bazaar log file) being created or configure it to be in ~/.bazaar/ instead of ~/?

Is there a way to tell bzr not to log everything into ~/.bzr.log or alternatively configure it to drop the log file into ~/.bazaar/` instead?
The environment variable BZR_LOG allows to
suppress the creation of the log file by setting it to /dev/null on unixoid systems and NUL on Windows.
create the log file in an alternative path by pointing it to that path, e.g. export BZR_LOG=$HOME/.bazaar/bzr.log on a Linux.
Configuration:
In Linux and other unixoid systems you can either use the system-wide setting under /etc/profile or $HOME/.profile (or $HOME/.bash_profile and $HOME/.bashrc.
In Windows you can set the variable by right clicking Computer then Properties on the desktop, then choosing Advanced system settings in the left pane and from there the button Environment variables. The dialog which pops up (screenshot below) allows you to set new variables or edit existing ones. Here's how it looks on Windows 7:
Rationale: it took me a while to figure it out and the search term .bzr.log, even when quoted, would end up with pointers to bzr log or this question: Where is the format of the file `.bzr.log` documented? None of this was particularly helpful, so I thought I'd share the found fact Q&A style for future internauts researching that same topic.

Is it possible to call an application selection window (Right click->Open With->Other) from the linux console?

On Gnome/KDE you can select in which application you want to open file (Right click on file -> Open With -> Other). Is it possible open file that way, but from console?
For example: you print " file.ext" and instead of opening in concrete application, there are that application selection window forced and then users chooses - starts selected program.
I tried to figure out that myself, but not found anything like that.
"edit file.ext" doesn't fits my needs, because it starts preferred application and you cannot choose which. And also on my desktop it says:
"Error: no "edit" mailcap rules found for type "image/jpeg"
So, am I able to forse that "open with" window from console? If yes, can you say how?
Both on windows and mac you can do such things.
//edit at 2009-02-10 14:17
Thank you very much for answers. Command will be used in program code, so unfortunately probably I would not be able to make some extra bash scripts.
For GNOME:
gnome-open <file>
For KDE:
kfmclient exec <file>
These commands should open up the <file> in the preferred application in GNOME or KDE respectively, although I don't have an installation of either to test on.
Take a look at man run-mailcap, you can change or add selected applications for each mimetype modifying the /etc/mailcap, ~/.mailcap files and some others.
Traditionally, on Unix systens (and therefore Linux, too), you start applications from the console (and not from a UI). The command line (or console) expects you to enter the name of the application and then the filename (plus some options).
This allows to use applications (or commands) in shell scripts.
On Windows, there is no real console (the DOS box is just a reminiscence of the dark ages of MS DOS). So the MS developers came up with the idea to have the OS treat anything as a command. If it's not a real command or application, the OS will determine the file type (by extension on Windows and by some header information on Mac). For each file type, there will be an associated application in a look up table.
This is why on Windows, it appears that you can enter the name of a file on the console and you will get the application to edit that file.
If you want a quick way to fix this in the Unix console, create a script called "open" or "o" and use the file command with the option --mime to identify the file type. You can then use a case statement to launch your favorite editor.
As for the error about "mailcap rules": There is a file called "mailcap" on Unix where you can define abstract "commands" (open, edit, view, print) for file types. See the mailcap man page.

Resources