Issue with windows shell right click extension in folder background - windows

It is very simple to add a custom command to the shell context menu like so:
[HKEY_CLASSES_ROOT\Directory\Background\shell\TestCommand]
#="My Test Command"
[HKEY_CLASSES_ROOT\Directory\Background\shell\TestCommand\command]
#="notepad.exe"
This adds a custom command to the right-click menu that launches notepad. Since I added it in Directory\Background\, my understanding is that the command should only show up when I right-click in the background of a directory (for example, right clicking an empty area in the right pane of Windows Explorer).
My issue is that the command is also showing up when I right click on an item in the left pane of Explorer (i.e. right clicking on a drive or folder in the treeview). Is there any way to prevent this from happening? I am launching a custom application with arguments and the result is unpredictable if the user is able to launch it from the left pane.

Add;
[HKEY_CLASSES_ROOT\Directory\Background\shell\TestCommand]
#="My Test Command"
"NoWorkingDirectory"=""

Related

Open a folder in vscode through Finder in macOS?

On my windows pc, I would just double click a folder and click "Open in VS Code" to a open a folder, which saved time for me when looking through lots of code online. With Mac, however, I do not have this option. I have to directly open vscode and click "Open" to open a new folder. How do I directly open a file in vscode through finder in macOS?
2023 Update - Use Native Method
Open the Command Palette (Cmd+Shift+P) and type shell command to find the Shell Command: Install 'code' command in PATH command.
Restart all terminal sessions for the new $PATH value to take effect.
You'll be able to type code . in any folder to start editing files in that folder.
If you want to do it in Finder, you can write an Automator script to do it (it's easier than it sounds, AND shows you the power of the OS).
Launch Automator
Create New Document
Create a new Quick Action
Add the Action... (New Method - 10.13+)
Workflow receives current files or folders from Finder.
Add a new "Open Finder Items" action to the workflow. (drag the "Open Finder Items" object, highlighted in the screenshot, to the empty window on the right)
Select "Visual Studio Code" from the list.
Add the Action... (Old Method)
Workflow receives current files or folders from Finder.
Add a new Run Shell Script action to the workflow. (drag the "Run Shell Script" object, highlighted in the screenshot, to the empty window on the right)
Configure the Workflow (Old Method)
Set the Pass Input to be as arguments
Paste the following in the input box:
open -n -b "com.microsoft.VSCode" --args "$*"
Save the action using a name like Open in Visual Studio Code.
You may now right-click on the folder and find your newly created task under Quick Actions.
The simplest solution is to create a Quick Action with Open Finder Items:
This way you don't need a shell script that might break with an OS update or VS Code update
Launch Automator and select Quick Action or File > New > Quick Action If Automator is already open.
Set Quick Action receives selected to files or folders and in to Finder.
Choose an Image (icon) select Choose.. and double click Visual Studio Code in the window that pops up, this will set your quick action icon to the same as VS Code
Add Open Finder Items, Choose open with as Other.. select Visual Studio Code and save your Quick Action as Open in VSCode optionally choose an Image for your Quick Action job done.
Finally just hit Cmd+S to save and name it Open with VSCode
Well you need to understand. macOS has different ways to do things than windows and initially it might be a challenge. For starters you start to make use of Terminal. its beautiful.
Now answering your question.
Open your VS code and then, press CMD + SHIFT + P, type shell command and select Install code command in path. Afterwards, navigate to any project from the terminal and type code . from the directory to launch the project using VS Code.
Using the new shortcuts app.
Download:https://github.com/gluedpixel/shortcuts
Or create it by yourself
Open Shortcuts app > Quick Actions
Change from receive any to Files and Folders
Add run shell script action
Paste the code open -n -b "com.microsoft.VSCode" --args "$*"
Change input to Shortcut input
Click on Shortcut input and set type to "Folder" & Get to File Path
There are some ways suggested here in the VS Code GitHub Issues tracker, but I would go with the first option of dragging the folder onto the app icon if you have VS Code icon in your dock!
If you really want to be able to do so from a right click, then this repository has a workflow solution. https://github.com/Sankra/OpenFolderInVSCode
Drag and drop the folder from Finder onto an empty VSCode window.
Found a way to achieve a 'Quick Action' that met my needs using the following steps using MacOS' Shortcuts app (No Automator needed):
if you are looking for screenshots as well, I wrote a small Notion page
Open the ‘Shortcuts’ app on your Mac
On the Left Pane, navigate to ‘Quick Actions’
On the top bar, press the ➕ button to add New Shortcut.
Click on ‘Any’ and change to ‘Files and Folders’ by selecting only those from the dropdown that appears on clicking the ‘Any’ field.
Click on ‘Action Library’ on the right pane and search for ‘shell’. Drag and drop the ‘Run Shell Script’ onto the main pane. This will add the action to the Shortcut’s flow.
In the shortcut details (on the right pane), make sure Use as Quick Action is ticked and so are ‘Finder’ and ‘Service Menu’.
In the newly added action called ‘Run Shell Script’ write “code “ and right-click to get the below pop-up, go ahead ‘Insert variable’ and then ‘Shortcut Input’.
Click on the ‘Shortcut Input’ tag that appears. A pop must appear, choose ‘File Path’ and just click anywhere else. This will change the tag to ‘File Path’.
Set ‘Pass Input:’ option to ‘as arguments’.
Be sure to set a cool name for your new Shortcut! I named mine a boring “Open in VSCode”.
Open a new ‘Finder’ Instance, right-click on a folder, go to ‘Quick Actions’ > ‘Customize...’
Make sure your Shortcut’s Name is selected. Exit the dialogue and Test!
There is a Terminal command named code, I would stick with it and you should get used to it as well if you are regularly using VS.
Follow the one-time setup with-in VS Code
Open your VS code and press ⌘ CMD + SHIFT + P
Type shell, and select Shell Command: Install 'code' command in PATH from the list
Open Terminal and hit any of the commands below:
code <path-to-folder>
OR
cd <path-to-folder>
code .
OR
cd <path-to-folder> && code .
I've actually managed to have it as an icon you can just add to the Finder window as such:
The script will allow you to open the current folder path in VSCode.
The steps to do so are:
Create a new Application with Automator
Select the "Run shell script" from the menu and drag it to the editor
Paste the following small script to the text area:
finderPath=`osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)'`
open -n -b "com.microsoft.VSCode" --args "$finderPath"
Save the Application to the Applications folder
Right click the app and drag and drop your desired VSCode icon to the blank area to the left of the name and close the Get Info window
Press and hold the Command key and drag the Application to an empty space in the Finder title row like in the picture
Test that it works by pressing on the icon. VSCode should now open with the content of the current folder in the navigation bar
Here is an alternative derived from the accepted answer.
Indeed the accepted solution by #jnovack just opens VS Code for me, but not the desired folder. If VS Code is already running it just switches the focus to a running instance of VS Code.
Solution
Provided that you have the code CLI command installed (if not, go to VS Code and do CMD+SHIT+P>"Shell Command: install 'code' in PATH")
Then open a terminal and run which code. You should get the code executable path looking somethin like /usr/local/bin/code
Then, as per #jnovack 's answer,
Open Automator
Create a new Document (CMD+N)
Create a new Quick Action
Workflow receives current files and folders from Finder.
Add a new Run Shell Script action to the workflow. (drag and drop the "Run Shell Script" object)
Pass input as arguments
Paste this code in the shell command field /usr/local/bin/code -n "$*" or replace with your path to the code executable if it differs from this one.
Save the action
Tbh. I would have expected to be able to use just code -n "$*", but for some reason, the PATH used by the automator's shell seems to be different from that used in the terminal. I'd welcome some input on that matter.
I find this to be the best solution out there:
https://github.com/RoadToDream/SzContext

Is there a keyboard shortcut (hotkey) to open Terminal in macOS?

One of my primary tools used for programming is my Terminal. It makes my programming process more efficient when I'm able to quickly open a Terminal window.
In Ubuntu, I was using (window+Alt+T) to open Terminal. But now I use a Macbook at my programming job.
Sometimes I use Spotlight to search "Terminal", and press Enter.
I'd like to know if I can assign a keyboard hotkey to do it.
I tested the following procedure under macOS Mojave 10.14.6 (18G3020).
Launch Automator. Create a document of type “Quick Action”:
(In older versions of macOS, use the “Service” template.)
In the new Automator document, add a “Run AppleScript” action. (You can type “run applescript” into the search field at the top of the action list to find it.) Here's the AppleScript to paste into the action:
on run {input, parameters}
tell application "Terminal"
if it is running then
do script ""
end if
activate
end tell
end run
Set the “Workflow receives” popup to “no input”. It should look like this overall:
Save the document with the name “New Terminal”. Then go to the Automator menu (or the app menu in any running application) and open the Services submenu. You should now see the “New Terminal” quick action:
If you click the “New Terminal” menu item, you'll get a dialog box:
Click OK to allow the action to run. You'll see this dialog once in each application that's frontmost when you use the action. In other words, the first time you use the action while Finder is frontmost, you'll see the dialog. And the first time you use the action while Safari is frontmost, you'll see the dialog. And so on.
After you click OK in the dialog, Terminal should open a new window.
To assign a keyboard shortcut to the quick action, choose the “Services Preferences…” item from the Services menu. (Or launch System Preferences, choose the Keyboard pane, then choose the Shortcuts tab, then choose Services from the left-hand list.) Scroll to the bottom of the right-hand list and find the New Terminal service. Click it and you should see an “Add Shortcut” button:
Click the button and press your preferred keyboard shortcut. Then, scratch your head, because (when I tried it) the Add Shortcut button reappears. But click the button again and you should see your shortcut:
Now you should be able to press your keyboard shortcut in most circumstances to get a new terminal window.
As programmers we want the quickest, most fool-proof way to get our tools in order so we can start hacking. Here are how I got it to work in MacOS 10.13.1 (High Sierra):
Option 1: Go to System Preferences | Keyboard | Shortcut | Services.
Under Files and Folders section, enable New Terminal at Folder
and/or New Terminal Tab at Folder and assign a shortcut key to it.
Option 2: If you want the shortcut key to work anywhere, create a new Service using Automator, then go to the Keyboard Shortcut to assign a shortcut key to it. Known limitation: not work from the desktop
Notes:
If the shortcut doesn't work, it might be in conflict with another
key binding (and the OS wouldn't warn you), try something else, e.g.
if ⇧⌥T doesn't work, try ⇧⌘T.
Don't spell-correct MacOS, that's not necessary.
iTerm2 - an alternative to Terminal - has an option to use configurable system-wide hotkey to show/hide (initially set to Alt+Space, disabled by default)
There is a third party app called hotkey app which can launch apps based on the configured shortcuts.
You can install it and setup required shortcut.
https://codenuts.de/en/posts/hotkey/
As others mentioned already, use the keyboard shortcut from services. I also had to restart the computer to take into effect.
mac - "command + t" will open a new terminal window.
Try command + t.
It works for me.

Xcode - open current file in a NEW window (a real challenge !)

Say you have File.m showing in the blue area above.
I want File.m to open in a new separate window.
How to do this??
Note that - of course - IF you have the ProjectNavigator showing and IF you can see the filename "File.m", then double-click on the filename and it will open in a new window.
What I want to do is open ANOTHER copy of the "CURRENT" file (the one in the primaryEditor) in a NEW WINDOW - without touching the ProjectNavigator.
Any ideas? Cheers
Note that ... (an excellent page here)
http://realmacsoftware.com/blog/xcode-4-s-less-obvious-shortcuts
if you click on whatever file is in the current primaryEditor, then shift option apple comma that will indeed open the following "freaky little-known Xcode popup" ...
you can then, indeed, choose to open a new window. (So to be clear, that is exactly what I want to do.)
So, I want to be able to do that in one step. Cheers!
In XCode's Preferences you can change the following:
And then right-click within the primary editor and click "Open in Separate Window"
Edit:
Instead of right clicking in the primary editor you can simply type command+option+, (comma)
Open the file what you want to open in the NEW window.
Command + Shift + t
Open the file what you want to open in the separated window.
Command + Option + ,
I wrote a new automator service that does the following steps in Xcode:
Execute the default shortcut for the "Open in..." menu item (Command-O)
(if this isn't your current "Open in" shortcut, the workflow will not work. If you still want to test it, just changed your default shortcut :) )
Go all the way to the left in the weird "Open in" view
hit Enter
Current file opened in new window
The only thing you need to do is install the service on osx and map a shortcut to it.
Here a download to the service:
https://www.dropbox.com/s/486t2iz17o0l9dh/Open-New-Window.zip
INSTALL INSTRUCTIONS
1.Place Service file in folder ~/Library/Services
2. Open "System preferences"
3. > Keyboard
4. > Tab "ShortCuts" > "Service" > "General"
5. > Set your own shortcut for the service
6. Go to XCode and test the service by using your very own shortcut
Tested on OS X Mavericks, Xcode 5.0.1
In XCode 4 you can have a split window via View -> Show Assistant Editor. Then choose the same file which you have already opened in the Primary editor by the small right arrows on top of Assistant Editor.
Thanks
in the ProjectNavigator. If you see the file name: Double click on the file name. It will open in a new window.

How do I paste long arguments into the debugger in Windows?

I'm trying to write my function's arguments in a text editor and paste them into the console, but the console won't let me.
(My list of arguments is long and the formatting starts to go crazy.)
I'm using ghci running in a cmd.exe window.
What can I do?
As pointed out in the comments, in a windows console you can right-click the title bar and do Edit > Paste.
If you'd rather just right-click in the window to paste immediately, you can turn on QuickEdit Mode:
Right-click the title bar of the window, and choose Properties.
Select the Options tab
In Edit Options, tick QuickEdit Mode
Click OK, and when it asks you, choose
Save properties for future windows with the same title. This means it'll happen every time you run ghci.
Works under XP, and as far as I can tell via Google, the same trick works in Vista and Windows 7.
This also has the effect that you don't need to choose Edit > Mark to select text. (Press enter after selecting to copy, and of course, right-click to paste.)

Windows Explorer Context Menu Integration, get file that was right clicked on

I've already figured out how to add a menu item to the right click context menu of the windows explorer using the registry. I currently have it set to launch my application when my menu item is clicked.
However, I want to know if there is a way to know what file is was right clicked on. I thought it would have been sent as a command line argument to the launched program, but it's not. Any ideas?
Add %L in the command line for the application you are launching at the place where you want the file name.

Resources