Batch copy file name action in Apple Script for Automator Mac OS X - applescript

Can one automate the process of copying a file name and pasting it in the Spotlight Comment box of that file? How does that Apple Script for OS X looks like?
I would need to do that a thousand times otherwise:
Hitting enter to select the file
Short cut typing Hotkey Cmd C
Short cut typing Hotkey Cmd I to open that info window
Hitting tab button twice to enter the Spotlight Comment box
Short cut typing Hotkey Cmd v
Short cut typing Hotkey Cmd w to close that info window
The aformentioned folder contains a thousand files and even more.

Automator has that function built right in, via the Set Spotlight Comments for Finder Items Action:
You should be able to point the first action at your target folder, have it find all the files, and it will add the Comment to all of them.
Good luck,

Related

Automator Quick Action Only Runs in Automator and not in Finder Quick Action Menu

I have an Automator Quick Action (QA) which calls a bash script to act on files within a specified folder. It works great when run inside Automator. But invoking the Quick Action from Finder by right clicking on the input folder does nothing with no errors or log files (as far as I can tell). screenshot of Automator code at link. My first bash code, and first question on stack-overflow - thanks to anyone in advance who might be able to assist. Apple silicon mackbook pro; running Mac OS 12.4.
Additional Info: The QA gets a selected folder and passes it to the bash shell script via "$a" argument. The selected folder will contain text files (.SRT) and movie files (.MP4). The bash script does some text parsing and passes on arguments to the Exiftool program which adds GPS metadata to the movie files.
Workaround found: I was able to import the automator workflow into the Mac OS Shortcuts App and the automation ran successfully via a menu bar command on my Mac.
I had the same issue for a long time trying to invoke a python program from bash shell script using quick action. It runs with no error in the editor and would run only if I left the workflow open all of the time in Automator. I eventually stumbled across a permission issue with Automator itself. I hope this could help you maybe?:
1 - Go "System Preferences -> Security & Privacy -> Privacy"
2 - Select "Accessibility" from the left-hand menu.
3 - Unlock to make changes, if necessary, then click the "+" sign at the bottom of the right-hand menu.
4 - Add "Automator" as a trusted app.
Hope it helps!

How to create dock icon for running terminal command in Mac OS

Now I open jmeter using terminal using command: open /usr/local/bin/jmeter
I need it frequently, so I want to create dock icon to run this command.
How can I do it?
I tried to make a right click and choose 'keep in dock' option. However, it disappears when I close the application.
The closest I could get was creating a desktop icon through the following method:
Create a plain text document in TextEdit
Paste the following code in the document
#!/bin/bash
open /usr/local/bin/jmeter
Save the file as fileName.command
Open Terminal and navigate to the directory which you saved the file
Type in chmod +x fileName.command and hit enter
You should now have a shortcut to execute this command! I know this isn't the exact solution you were looking for, but I hope this still solves your problem.
Following E. Zimbelman's answer, you create a .command executable file and then
you can add an icon (drag and drop an icon file on the icon of the properties window of the file (Cmd+I))
change the .command extension to .app
so you can add it the the dock (drag and drop), it's ok if the icon has changed temporarily
and then you change it back to .command
With this you can have any script you like in the .command file and have it on mac's dock.
I suggest you have a look at the answer to this question in the apple stackexchange. It pretty much does exactly what you want (although I have no idea what jmeter does).
The answer is, essentially, use automator to run your script, save the automator job as an app (not a workflow), and drag the resulting object to the dock, once you have it working the way you want.
https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock
or the wayback machine copy:
https://web.archive.org/web/20160921184459/https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock
I needed a simple terminal command to unmount an internal disk which keeps spinning up whilst appearing in Finder to be unmounted. I am running the Mac from an external SSD.
All that was required was to open Script Editor and enter the text:
do shell script "diskutil eject /dev/nameofthedisk"
and then save that as an Application. Drag that to the dock and now I have one click unmounting of the disk when it spins up.

a basic keystroke map

I downloaded AutoHotKey today and read the tutorial. What I want to do is have an F2 key do a shift-ctrl-S in one application. I cannot figure out how to do that by reading the tutorial. How can I do it?
Firstly, install autohotkey on your system.
Once installed, create a text file and save it as .ahk (rather than .txt).
Within the file, at the end, type the following code:
F2::Send +^s
Save the file then double click it to run the program.
This will change F2 to your shift-control-s in ALL applications.
To make it application-specific, when running, right click on the icon in the taskbar and choose "Windows Spy". Click into the application you want to use the F2 shortcut in and make a note of the line just below >>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Now, change your script to this:
#IfWinActive INSERTWindowsSpyWindowTitleHERE
F2::Send +^s
#IfWinActive
Obviously making sure to change INSERTWindowsSpyWindowTitleHERE to what you got from windows spy.
Save and run your script. Autohotkey will now only make F2 do that shortcut when the window (found via Windows spy) is active. (The last #IfWinActive is used to "reset" checking for that window in code below where this is typed - useful if you're going to type more autohotkey code in the future)

AppleScript to paste text from clipboard into a file

I thought this would be easy. The Google makes me think otherwise.
What I want is a poor man's inter-OS clipboard. Everything I looked at on the net is either not free, no app this simple should cost anybody anything, or isn't compatible with local linux installs or Windows or some such.
In the best solution a right mouse action would be added to "cut", "copy" and "paste" named something like "copy to file". The file might or might not exist but would have a fixed name and be on a shared disk.
I guess I'd need a second right mouse action "Paste from file" to complement the "copy to file".
So, would some one show me how to have an AppleScript or, maybe, Automator, take the current text contents of the clipboard and paste into an existing file, overwriting any
existing contents of the file?
OS/X Snow Leopard
Thanks.
how to have an AppleScript […], take the current text contents of the clipboard and paste into an existing file, overwriting any existing contents of the file
AppleScript code:
do shell script "pbpaste > /path/to/your/clipboard-file.txt"
In order to read text from the file back into the clipboard, use
do shell script "cat /path/to/your/clipboard-file.txt | pbcopy"
For documentation, see man pbpaste
EDIT: Now, to convert the AppleScript into a Mac OS X Service, which will appear in the "Services" group of every context menu (at right-click / CTRL+click on any text), you can use Automator, as described in this tutorial.

"Open folder in Terminal" for Spotlight or Alfred

Is there any way in Spotlight to have a folder open in a Terminal window, either by providing an "Open in Terminal" option in search results, or (ideally) by holding down a key when selecting a result? Basically the same way holding down command will "Open containing folder" maybe make it so holding option (or whatever key) could "Open in Terminal".
Alternately, is there a way to setup the Alfred app so that it will always open folder search results in the Terminal? that might be even better, then I could use ctrl-space exclusively for opening folders in the Terminal and command-space (Spotlight) for everything else.
The closest thing I can find to anything like these is the "cdto" application, which adds an "Open in Terminal" button to the Finder. This is nice, but being able to do this directly from Spotlight or with a keypress would be much more convenient.
This question is old and you undoubtedly found the answer by now; for the sake of completeness: the latest version of Alfred allows one to search/navigate the filesystem from within Alfred, and take action on the folder or file found. One folder action is "Open Terminal Here", which seems to be what you are asking for.
I've found this to be the fastest method without any external tinkering.
Requirement: need to have iTerm or Terminal in the Dock:
Type the folder name into Alfred / Spotlight
Click and drag the folder that was found into the iTerm / Terminal icon in the Dock
Try this tool:
https://github.com/nmadhok/OpenInTerminal
This is a really handy tool for programmers on Mac as it lets you open the folder directly in Terminal. You can select multiple folders to open them in multiple terminal windows. You can also select files to open the parent directory in Terminal. This application works with Finder as well as without Finder which is a plus!
use this Alfred extension
https://github.com/LeEnno/alfred-terminalfinder
then just lob off the input and set it to a hotkey.. I have one to open the current finder in terminal and vice-versa
#Verboze - I'm still looking for an answer :)
Perhaps it should be migrated to stack exchange or the other one used non-programming topics, such as system administrivia. Though a case could be made that the command line is essential to programming.....
Windows has "Command Prompt Here". Linux has Nautilus' "Open In Terminal". The world's most advanced operating system has nothing (the best I can tell).
For completeness, I did look at the customizable toolbar ('drag your favorites here'; but my favorite is missing). I also found an old Action Script or Automator Script that did not work (the article was old, and it could not be followed).
I did find a program called "CD To...", but its broken. Upon opening the first terminal, the program opens two terminals. I'm not sure what other programming mistakes were made by the developer, and I really don't want to experiment.
Check this: https://github.com/miromannino/alfred-new-terminal-window
It opens a new Terminal/iTerm window in the current space.
Holding the alt key, the new window is also opened opened in the current frontmost Finder folder.
For me that is almost sufficient for my daily work!
Hope it helps!

Resources