Adding environment variable to a commandline argument in a windows shortcut - windows

So I'm trying to make a mailto link on a windows desktop. This is to automate opening a mail client by inserting the recipient and subject automatically. I can do just that, however I'd like to include either the current date or the previous date in the beginning of the subject line. I've tried:
%windir%\explorer.exe mailto://user#email.com?subject=%date% 'Rest Of Subject'
and every other variant I can think of. The link either reads %windir% correctly or just skips it but opens fine. However, I see the literal '%date' in my subject.
Is this possible without using batch files or scripting? This is for work different computers at different locations, where users aren't exactly computer savvy and need things done for them. Also for bonus points, is there a way the also make the file attach dialog pop up? The purpose of this is to send security log word document from different locations to a central email address. Thanks and I hope to hear from anyone who can direct me where to look or give me some hints on my command line fu!

Related

Win CLI open file with "How to open"?

I need to open the file using Windows 10 cmd. But when the file opens, I need Windows to show me a modal window "How do you want to open this file?". The system should do this even if it already has a program selected by default to open a certain type of file. Is it possible to do this?
To clarify my problem:
I need the console to run for example ".py" not through the standard Python.File="C:\Windows\py.exe " "%L" %*, and for example via VS Code. You might tell me about the VS Code CLI. But how to handle an event where the user will not have VS Code, but for example Pycharm, and the user will want to open it through it? That is why the question was posed in such a way that the user could choose through what to open the file already through the built-in modal window in Windows. In any case, I will be glad of any suggestion to solve my problem.
I tried to find something similar, but apart from the standard start something.som I didn't find it. And this is not a solution to the problem, because start starts the file in the program that is specified by default in the system. This program may not even be the one that the user ever chose later. I came across a similar question in Stackoverflow, where a person wanted to see which program was responsible for opening a file with a certain extension, where assoc and ftype were used, but they did not give the desired result.

On a Mac: Can I create a key shortcut to run a bash code based on clipboard content

It has been a while since I coded a little bit and I only use Mac for a couple of weeks.
Here is what I would like to do:
I have a spreadsheet with email addresses, subjects and text bodies for an email.
I can summarize this data in a way that I have a cell that is filled with
to=foo#nowhere.net,subject='test subject',body='test body'
Now, I would like to copy this line to clipboard and create a keyboard shortcut to run this code
cd /Applications/Thunderbird.app/Contents/MacOS/
./thunderbird -compose "CLIPBOARD CONTENT"
I would like to use this to automatically create an email based on the (dynamic) content of the spreadsheet.
Is this possible or does anyone have a better idea how to create such emails? I have tried to work with mailto-links but it does not work because there is some more complexity to the spreadsheet which makes it impossible.
Thank you!
This workflow works from within Automator (even though I feel it's kind of buggy). Unfortunately, when I call it using a shortcut from within other apps it throws an error:
Found the cause of my error 212:
The of front workflow statement does not work from outside Automator because then, it is not the front workflow anymore. I had to do a workaround that does not use this statement...

FTYPE/ASSOC priority and adding to OpenWithList from the command line

(Not sure if this belongs on superusers, but it seems there is a cmd.exe tag here, so here goes...)
As background, I'm working on a Firefox add-on (This question does not require knowledge of Firefox, btw, as Firefox add-ons can call the command line.) The add-on aims to build different kinds of shortcuts to cmd.exe (especially for the sake of my project https://github.com/brettz9/webappfind which allows files to be opened directly from the desktop into web apps).
Anyways, I'd like to give users the option to associate these shortcuts:
As the default handler for specific file extensions or file types.
To show up within the Open With list of applications (even if the user opts not to make the apps as default handlers)
As far as the default handling, I have found the ftype and assoc (and associate) commands, but I have read that user selections will override their behavior. Is there some way to ensure that I can get priority from the command line in associating file extensions to types and specific executables (until the user changes it again), or if it is not possible, then at least through C++ or the like?
As far as the Open With list:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\<file extension>\OpenWithList
...in my testing (with an exe), this command:
reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.svg\OpenWithList /v d /d D:\wamp\www\webappfind\cplusplus\WebAppFinder-view-mode-Firefox.exe
...did cause the exe file to show up in:
reg query HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.svg\OpenWithList
...but it did not show up when I subsequently right-clicked a file with the ".svg" extension.
I would really appreciate any help with these two points.
REGEDIT4
[HKEY_CURRENT_USER\Software\Classes\Applications\MYFOO.exe\shell\open\command]
#="\"C:\\MYFOO.exe\" \"%1\""
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.myfoo]
"Application"="MYFOO.EXE"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.myfoo\OpenWithList]
"a"="MYFOO.EXE"
"MRUList"="a"
So I got to an investigation what makes those file associations. It appears that you have to create a mapping from the bare EXE name to the full path as shown in the first two long-ish lines. Then you must only use the EXE name in the .extension branch. Setting the .extension's Application value will give you your default app instantly. Remember, only use APP.EXE, its full path must be defined as above. This was your main error. The "%1" part allows you to customize the parameters of your program so that it doesn't have to be just the opened document in quotes, as shown here. The backslashes are just escape characters for Regedit, you may discard them as you see fit.
The OpenWithList is tricky in the sense that there are letters for entries and just a blind write may overwrite some of the user's favorite apps. One approach would be to call your item "z" to lower the probability of overwriting. The right way would be enumerating the key and giving your app the first free letter. The MRUList is not essential, although it should have each used letter once and yours bumped to the start.
Note about user friendliness: Explorer will cache these values until next reboot. Make sure you update the registry and place exe first and create your file later. Although the caching only fully influences the display of the file and when it is run, the registry is read again and it will execute as you want.
TIP: If you decide to use Regedit instead of reg, the /s parameter skips the confirmation message and applies the values right away. Make sure you use double backslashes in the full path as shown. When preparing your temporary .reg file, make sure you append two CRLF's to the end or a glitch may cause your last line of code to be ignored. This sample starts with REGEDIT4 which signifies an ANSI file. If you need support for Unicode in your app path, you'll have to start the file with Windows Registry Editor Version 5.00 and store it in UTF16. This is already a superior solution to calling reg because there's no way you could get CMD.EXE to process special UTF stuff through the command line without mangling.

Can the last opened file location be directly altered?

As I understand it, when a file open dialog box (such as GetOpenFileName) is used, Windows will automatically remember where the last file was that was opened by the program, and Windows remembers these locations separately for each program. Is there a way to directly alter this, in order to cause the file picking dialog for program X to start in C:\Example\Directory?
I'm attempting to automate a program which has been programmed to work only through a GUI, and I don't have any access to the internals of this program (such as being able to alter how it calls the file picker). Instead, I'm using a mouse macro (via AutoHotkey). If I can be completely sure that the file picker will start in a particular place, I should be able to automate the rest with mouse clicks.
If you had access to the source code, I'd suggest you just change the lpstrInitialDir property of the OPENFILENAME passed to GetOpenFileName().
Outside of that, you'll want to change the registry keys for the MRUs:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32
What might make more sense, and might fix the issue you're having, is also changing the Working Directory so that the default location isn't "My Documents", if you're experiencing that.
Depending on the operating system, the results vary:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx

Where does Windows store its "Open With" settings?

I'm trying to programmatically check file associations by the file extension (for example .jnlp files). I keep reading that
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\JNLPFile\Shell\Open\Command
is the Registry key to check. However, if you change the association through Windows Explorer:
Open With > Choose Program > (Always use the selected program)
the change isn't at all reflected in this Registry key. Where else is this information stored?
Take a look in:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
and the sub-key of that is the extension you reassigned. Under that there will be the UserChoice and OpenWithList sub-keys which will contain your redefinition.
You may also want to read http://support.microsoft.com/kb/950505 which talks about your issue.
Update
As of Windows 8, life has gotten far more complicated. To create an extension association a custom hash needs to get calculated.
Fortunately, someone has reverse engineered the process and created a PowerShell script to do this without having to go through any GUI.
You can find it at the following GitHub link:
https://github.com/DanysysTeam/PS-SFTA
This is a two-part look-up.
First, you look up the default value of HKEY_CLASSES_ROOT\[file_extension]. For your extensions, .jnlp, the value is "JNLPFile". Let's call this the [file_descriptor].
Now you can look up the default value of HKEY_CLASSES_ROOT\[file_descriptor]\Shell\[action]\command (where [action] is the shell action you are interested in, e.g.: Open, Print, Edit, etc.).
On:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jnlp\OpenWithList
Tip: Edit>Find is pretty handy at these situations. :)

Resources