TCL/TK - Get Desktop path - tcl

My TCL/TK application prompts the user to choose a location where to save a file.
What should the value of the -initialdir option be so that the Desktop is the default location?
I tried %userprofile%\desktop, but it's not working.
set dir [tk_chooseDirectory -title "Where do you want to save the config file?" -initialdir %userprofile%\desktop]
Thanks

The safest way is to use twapi's get_shell_folder command with the argument "csidl_common_desktopdirectory" to get the path to the "all users" desktop directory, or "csidl_desktopdirectory" to get the current user's desktop.
If you don't want to depend on twapi, the paths can be found in the registry, but I don't know how reliable it is. For example:
package require registry
puts [registry get "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders" "Desktop"]
This returns "%USERPROFILE%\Skrivbord" on my system. You still have to expand the USERPROFILE variable (and any other variables). That's best done with twapi::expand_environment_strings, but since you're not using twapi, try regsub:ing %USERPROFILE% with $env(HOME) instead.
Or if you don't care about people with non-english Windows, just use "~/Desktop".

Related

How to set silent_functions(1) as default in Octave? [duplicate]

I'm new to octave, and want to run a few commands on startup automatically every time it opens.
I typed "help startup" and saw "Octave uses the file ".octaverc". I did a bit of searching online at https://www.math.utah.edu/docs/info/octave_4.html, and saw the .octaverc file should be in the following path:
OCTAVE_HOME/lib/octave/VERSION/startup/octaverc
PROBLEM:
In that directory I don't have a startup folder, only "oct" and "site". I do see hidden files, which was my first thought since the file begins with "." character. So I then used Agent Ransack in the directory, and still nothing came up.
QUESTION:
1) Do I have to make the startup folder and octaverc file myself?
2) If so, does one, both or none have to be hidden?
3) Can it be a txt file, or does it have a special extension?
4) Do I just type the commands straight into the file or is there special formatting?
NOTE:
In case I'm going about this the wrong way, there are the operations I'd like to have run on startup:
PS1('>> '), addpath('D:\Users\Me\Desktop'), clc
Thanks ahead of time for the help!!
Possible locations (and their differences) for octaverc files are specified in the documentation.
In short, these are, from more general to specific:
octave-home/share/octave/site/m/startup/octaverc (most generic, for entire system)
octave-home/share/octave/version/m/startup/octaverc (to cover for more than one octave versions installed on the system, possibly requiring different startup scripts)
~/.octaverc (where ~ is unix-speak for a user's home directory -- covering for user-specific startup files)
.octaverc files in any directory, creating specific startup conditions for specific directories
octaverc files are effectively simple script files that are executed from most generic to most specific each time octave starts. Therefore, in the presence of conflicting commands, the more specific file can effectively be used to override the more generic behaviour.
Octave also supports (but does not recommend) the use of the startup.m file, for matlab compatibility.
You might also want to check out pathdef and savepath as well.
As a more general tip, if you ever want to search for a specific keyword from the documentation (e.g. octaverc), you can type this kind of search query in duckduckgo (or google):
octaverc site:https://octave.org/doc/interpreter/
(or just download the documentation as pdf and search the pdf)
Found the solution, the file was in the following path:
OCTAVE_HOME/share/octave/site/m/startup
to find out where OCTAVE_HOME is for you, just type "OCTAVE_HOME" into your Octave command line window.
ANSWERS:
1) You do not have to make a startup octaverc file yourself
2) The file is actually not hidden, so it should be easy to find given you're looking in the right place.
3) The file doesn't have an extension. It's just octaverc.
4) Under the last line of the existing file, you can just append commands as you would type them at the Octave command line window.
the last(7.3.0) octave version placed HERE:/ does not find the THERE:/openEMS/matlab directory even it is already loaded with octaverc or addpath. It keeps looking into the work dir where openEMS is not placed and does not recognize, for instance, the 'physical_constants.m' file.

Dynamic User in .bat file

This is my first time trying to use .bat files. I am trying to make one that keeps my front end of my Access database on the most current version for users (only ~7).
I am using:
md C:\Users\tmyers\Desktop
del C:\Users\tmyers\Desktop\Quotations.accdr
copy "\Users\counter1152\desktop\PM DESKTOP FILES\Lighting Project Management Application\Quotations.accdr" C:\Users\tmyers\Desktop
C:\Users\tmyers\Desktop\Quotations.accdr
Part of the copy string I removed due to being the path to our server (just in case). I need the user to somehow be dynamic based on the person executing the file. I could make a special .bat file for each person since I dont have many users, but that seems sloppy.
As a secondary question, how can I get the cmd prompt window to not show when this is executed? That would just be a personal preference of mine. I did find https://superuser.com/questions/140047/how-to-run-a-batch-file-without-launching-a-command-window for reference but am not 100% sure how to do wscript.
try with :
md "%userprofile%\Desktop"
del "%userprofile%\Desktop\Quotations.accdr"
copy "\Users\counter1152\desktop\PM DESKTOP FILES\Lighting Project Management Application\Quotations.accdr" "%userprofile%\Desktop"
"%userprofile%\Desktop\Quotations.accdr"
To auto-hide the cmd.exe window you can use windowmode.bat and getCMDPid.bat:
call getcmdbit.bat
call windowmode.bat -pid %errorlevel% -mode hidden

Keyboard short for uploading two files in PhpStorm

The problem
In PhpStorm I have a style.css- and a app.js-file that I have to upload to a server over and over again. I'm trying to automate it.
They're compiled by Webpack, so they are generated/compiled. Which means that I can't simply use the 'Tools' >> 'Deployment' >> 'Upload to...' (since that file isn't and won't every be open).
What I currently do
At the moment, every time I want to see the changed I've done, then I do this (for each file):
Navigate to the files in the file-tree (using the mouse)
Select it
The I've set up a shortcut for Main menu >> Tools >> Deployment >> Upload to..., where-after I select the server I want to upload to.
I do this approximately 100+ times per day.
The ideal solution
The ideal solution would be, that if I pressed a shortcut like CMD + Option + Shift + G
That it then uploaded a selection of files (a scope?) to a predefined remote server.
Solution attempts
Open and upload.
Changing to those files (using CMD + p) and then uploading them (once they're open). But the files are generated, which means that it takes PhpStorm a couple of seconds to render the content (which is necessary before I can do anything with the file) - so that's not faster.
Macro.
Recording a macro, uploading the two files, looking like this:
If I go to the menu and trigger the Macro, then it works. So far so good.
But if I assign a shortcut key and trigger that shortcut while in a file, then it shows me this:
And if I press '1' (for it to upload to number 1 on the list), then it uploads the file that I'm currently in(!?), and not the two files from my macro.
I've tried several different shortcuts (to rule out some kind of keyboard-shortcut-clash):
CMD + Option + CTRL + 0
CMD + Shift 0
CMD + ;
... Same result.
And the PhpStorm Macro's doesn't seem to give me that many options anyways.
Keyboard Maestro.
I've tried doing it using Keyboard Maestro.
But I can't get it setup right. Because if it can't find the folders (if they're off-screen or if I'm in a different project and forgot to adjust they shortcuts), then it blasts through the rest of the recorded actions, resulting in chaos. Ideally it should stop, if it can't find the file on the screen.
Update1 - External program
Even if it's not possible to do in PhpStorm, - are there then another program that I could achieve this with?
Update2 - Automatic Deployment in PhpStorm
I've previously used this, - but I've had happen a few times that I started sync'ing waaaay to many files, overwriting critical core files. It seems smart, but can possibly tear down walls if I've forgotten to define an ignore properly.
I wish there was an 'Automatic Deployment for theses files'-function.
Update3 - File Watchers
I looked into file-watchers ( recommendation from #LazyOne ). Based on this forum thread, then file watchers cannot be used to upload files.
It is possible to accomplish it using external program scp (Secure Copy Protocol):
Steps:
1. Create a Scope (for compiled files app.js and style.css)
2. Create a Custom File Watcher with scp over that Scope
Start with Scope:
Create a Local Scope with name scp files for your compiled files directory (I will assume that your webpack compiles into dist directory):
Then, to add dist directory into Scope, select that folder and click on Include Recursively. Apply and Move to File Watchers
Create a custom template for File Watcher:
Choose a Name
Choose File type as Any
Choose Scope as scp files(created earlier)
Choose Program as scp
Choose Arguments as $FileName$ REMOTE_USER#REMOTE_HOST:/REMOTE_DIR_PATH/$FileName$
Choose Working directory as $FileDir$
That's it, basically what we have done is every time when a file in that scope changes, that file is copied with scp to the remote server to the corresponding path.
Voila. Apply Everything and recompile your project and you will see that everything is uploaded to the server.
(I assumed that you have already set up your ssh client; Generated public/private keys; Added a public key in your remote server; And, know ssh credentials to connect to your remote server)
I figured this out myself. I posted the answer here.
The two questions are kind of similar but not identical.
This way I found is also not the best, since it stores the server password in clean text. So I'll leave the question open, in case someone can come up with a better way to achieve this.

How do I configure fpp (Facebook Path Picker) to open new tabs in macvim using a vimer alias?

I believe that I need to set the $FPP_EDITOR environment variable to be able to change the default editor that fpp would invoke when opening files.
I have aliased mvim to vimer -t with alias mvim="vimer -t". This means that the mvim command should open new files in the currently available (operating system level) macvim window, and even if a sequence of files is included, it should open them in new tabs in that (operating system level) window. So if I already have an instance of macvim running and I try to pass in 4 files, I now have one window with 5 tabs in it.
But when I try to use mvim as the editor (with export FPP_EDITOR="mvim"), it opens the files in new macvim (operating system level) window, in separate (vim buffer level) windows in a single tab. So if I already have an instance of macvim running and I try to pass in 4 files, I now have two macvim "instances" running in separate OS-level windows, one with 1 tab with 1 buffer-level window, and one with 1 tab with 4 buffer-level windows.
It seems like FPP must be doing more than just passing in files in a sequence as a suffix to the $FPP_EDITOR command. I'm not sure what that is, nor exactly how to figure it out.
This is an answer to the question (technically) that I figured out as I was writing out the question.
But, it's missing all the right extra info about what was going wrong, so I'm going to this as an answer, but will happily accept another answer that can do more than just answer the question per se, but can give some background info about why the aliasing only sorta works.
The key though (if you just want a solution) is to use
export FPP_EDITOR="vimer -t"
and this performs as desired. For some reason it does not seem that setting the environment variable to a command that is aliased uses the aliased command, if it has an available original meaning (which mvim does).

mysql not in my PATH for some reason

I've installed mysql on several macs and on one of them mysql is not in the path. If I export it it shows up in the path correctly, but upon reboot, disappears.
What should I do to get the machine to keep it in the path and what are the machines that DO have it in their path doing differently?
Any thoughts appreciated.
Check the /etc/profile file on the macs it's working on. The path file should be defined there, which would be for all users. The ~/.bash_profile mentioned is for an individual user.
You should see something similar to the previously mentioned
export PATH=/path/to/mysql_folder:$PATH
in this file, though it may be a bit buried. If you don't see PATH defined here, try /etc/environment. Failing this, I'm not sure where else OS X would define the path variable, but being a Unix system, there is a common file read by all profiles where it sets it.
Once you find it, compare the definition on the machines it works on to the one it doesn't, and edit accordingly. If it looks the same, then something's amiss, and you should let us know.
if it is linux you have to add this export to your profile script. if windows edit PATH in My Computer | Properties | Edit environmental variables
To one of your init files (such as /home/username/.bash_profile) add a line like:
export PATH=/path/to/mysql_folder:$PATH