When you startup your machine, the first thing you do is to open the various programs you work with. Examples: your note-taking program, the pdf file that you need to read, the ppt file you were last working on, and of course your strongest link with the outside world nowadays; your email box. This post shows how to automate this process. Windows machines notoriously need restarting for every little (un)install. I trust you will find this startup automation advice handy.
The way to automate your workflow startup process is via the command shell.exec
. Here is how you can use it to open whatever it is you need:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
library(magrittr) a_pdf <- "path to pdf" shell.exec(a_pdf) a_tex_file <- "path to tex" shell.exec(a_tex_file) shell.exec("Path to your note taking program.exe file") shell.exec("Path to you-get-the-idea.exe file") |
I imagine you don’t often move around files once they are saved where they should be saved, so those paths are fairly fixed. You can use the a tip given in a previous post to quickly reverse the backslashes before pasting the path into your code editor.
You can open multiple files for the same application (e.g. multiple pdfs). You can also rework the code for a bit more elegance:
1 2 3 4 |
voila <- list(a_pdf, a_tex_file, application1.exe, application2.exe) voila %>% lapply(shell.exec) |
Open your default browser with the pages you use most. Those few lines should help you feel comfortable clearing your web cache and data saved by aggressive browsers, your starting point is here:
1 2 3 4 5 6 7 |
url1 <- "https://something something 1" url2 <- "https://something something 2" url3 <- "https://take me back to my gmail please" url_list <- list(url1, url2, url3) url_list %>% lapply(browseURL) |
For Python users, you can use the subprocess
module to do the same as.
1 2 3 4 |
import subprocess subprocess.call(['C:\Program Files\Mozilla Firefox\\firefox.exe']) |
Less mousing around, more CTRL + Enter.
One comment on “R tips and tricks – shell.exec”