Usually I get an excel spreadsheet with dozens of filenames, for which I then need to go and search individually.
Spreadhseet
Is there a way that I could simply:
Select All filenames in e.g. row A of Excel,
then Search for all these files on "This Mac"
then Copy all found files into the New Folder on the Desktop
So far I've tried the first part of searching and this is what i get :a)
Automator with Variable. But the problem is, it only searches for 1 file from selection
b)
Automator with Shell Script (Copy to Clipboard > Open Finder > CMD+F (to highlight Search dialog) > CMD+V). It opens a new Finder window, but it doesn't paste the clipboard into search dialog
c) /usr/bin/pbcopy
on run {input, parameters}
tell application "System Events"
keystroke "f" using {command down}
keystroke "v" using {command down}
end tell
return input
end run`
End result, is same as option b). I was planning to run this in Automator as a 'Service', which I could later assign to Keyboard Shortcut.
I am pretty sure there should be a simple shell option for this - any advice would be much appreciated.
I made a bash script that does what you want. You would basically select a bunch of filenames in Excel, or any other app, and copy them to the clipboard with ⌘C. After that you need to run the script and it will take items from the clipboard and search for TIFF or JPEG images that match that name and copy them to a directory on your Desktop called Selected Files:
#!/bin/bash
# Get contents of clipboard into bash array
files=( $(pbpaste) )
# Create output directory - no checks for already existing or already containing files
OUTDIR="$HOME/Desktop/Selected Files"
mkdir -p "$OUTDIR"
# Iterate through fetching files
for ((i=0;i<${#files[#]};i++)) ; do
name=${files[i]}
result=$( mdfind "kMDItemDisplayName == \"${name}.*\" && (kMDItemKind==\"TIFF image\" || kMDItemKind==\"JPEG image\")" )
if [ -f "$result" ]; then
echo $name: $result
cp "$result" "$OUTDIR"
else
echo ERROR: Searched for: $name, found $result
fi
done
I am not sure of your level of familiarity with bash, so you may be able to ignore the following...
Make a new directory for your own scripts:
mkdir -p $HOME/scripts
Save the above script in that directory with filename:
$HOME/scripts/gather
Make the script executable by typing this into Terminal:
chmod +x $HOME/scripts/gather
Edit your login profile ($HOME/.profile) and add your $HOME/scripts directory to your PATH:
export PATH="$PATH":$HOME/scripts
Then start a new Terminal and you can use any script that you have saved in $HOME/scripts without needing to specify the full path to it, e.g.:
gather
Following information kindly contributed by #user3439894 in comments section, as I am out of my depth on this aspect...
To use a keyboard shortcut, you'd have to create an Automator "Service workflow" with a "Run Shell Script" action, which you can assign a keyboard shortcut to under: System Preferences > Keyboard > Shortcuts > Services
Related
I tried to make a custom command that unzip a selected file to a path defined by user, but with a default value to current path and current archive name in remote server using this command, but the prompt just gave me an empty value. What's the mistake?
unzip "!" -d "!?&Extraction Path:?!/!!"
Thanks in advance!
It's not possible. There's actually a feature request for this functionality:
Bug 743 – Allow patterns in default prompt answer in custom commands.
Though even that it meant to support only static (non-file) patterns like !/, but not file patterns like !.
If it helps, in WinSCP extensions, it's possible to use non-file patterns, like !/ (but not file patterns, like !) in default prompt/option answer.
The extension file may look like:
#name Unzip...
#side Remote
#command unzip "!" -d "%ExtractionPath%"
#option ExtractionPath -run textbox "Extraction path:" "!/"
Just store the above script to a text file and install it to WinSCP.
Another thing that you can do, is to add a checkbox that will make WinSCP add an archive name (without an extension) to the path, with some clever use of shell (bash) constructs. This way, you can uncheck the checkbox and add a custom subfolder to the target path manually, if you do not want to use the archive name for the subfolder name.
#name Unzip...
#side Remote
#command unzip "!" -d "%ExtractionPath%`[[ '%AddName%' = '1' ]] && AN=! && echo ${AN%.*}`"
#option ExtractionPath -run textbox "Extraction path:" "!/"
#option AddName -run checkbox "Add file name to the extraction path" "1" "1"
Yet another alternative is to use your own placeholder for archive name (e.g. ARCHIVENAME) that will get replaced by real name (without an extension), when the command is executed. Then, if you do not want to use the archive name for the subfolder name, you replace the ARCHIVENAME with a custom name.
#name Unzip...
#side Remote
#command unzip "!" -d "`EP=%ExtractionPath%;AN=!;AN=${AN%.*};echo ${EP/ARCHIVENAME/$AN}`"
#option ExtractionPath -run textbox "Extraction path:" "!/ARCHIVENAME"
I'm trying to figure out how to add content/code to the end of a .js file that already has code in it using ssh command.
ie....
touch ./ap/includes/ckeditor/ckeditor.js
Maintain current code
echo "add custom end code only"> ./ap/includes/ckeditor/ckeditor.js
sshcommand is used to connect to another server.
What you can do append text to the end of a file is to echo "something" >> /your/file.
So based on your code:
touch ./ap/includes/ckeditor/ckeditor.js
Maintain current code
echo "add custom end code only" >> ./ap/includes/ckeditor/ckeditor.js
^
|_ changed this
By the way, the touch part is unnecessary. When echoing inside the file, the date of the file will be updated. And if file does not exist, it will be automatically created with echo.
From of the thousands and thousands of personal photographs in my collection, I'd like to select some special ones to print and display as a collage. All the photos are on one hard drive but scattered around /home/$USER. I know how to find all jpg photos with a command like this: find / -iname "*.jpg" -print. But that only lists the file name. I could run a similar command to view the file, but that is only half the challenge.
How can I then view each photograph and also have a dialog for whether or not to copy the photo to the directory that will be printed? (For example, with fdupes -r -d /home/$USER I can see a dialog about which file to delete.
(Some background, I used ubuntu 12.04 x64 and I'm comfortable with the terminal.)
# assuming you have $pic_list as an array of all images
# i.e. somethiing like pic_list=`find / -iname "*.jpg"`
for pic in $pic_list
do
display $pic & -OR- eog $pic &
echo "Press 'y' to copy $pic to /home/$USER/<dest_folder>"
read option
if [ $option = "y" -o $option = "Y" ]
then
cp -f $pic /home/$USER/<dest_folder>
else
echo "will not copy $pic"
fi
done
If this is not what you are looking for, pls do let me know.
1. Make symlinks to all the images in a single directory
mkdir all-pics
cd all-pics
find ~/Pictures/ -iname '*.jpg' | \
awk '{name=$0; gsub(/[/]/,"_", name);\
system("ln -s \"" $0 "\" \"" name "\"")}'
Note: The awk script generates and executes the command ln -s "/path/to the/original image.jpg" "_path_to the_original image.jpg" for each image found.
2. Use geeqie to view the images.
3. Use Ctrl+C shortcut to copy the current image to a separate to_be_printed/ folder. geeqie's copy dialog remembers the last selected folder, so you'd only be pressing Ctrl+C, Enter to copy the picture.
There are many ways to solve this problem. I personally always found e.g. qiv a nice tool for some problem like this. You can easily configure it to read a qiv-command config where you can exactly script what you want to do on a particular keypress. I use it for a similar task as you do and just keep my fingers on d (delete), space (next).
e.g.
https://bitbucket.org/ciberandy/qiv/src/3b3fb21db52c076cd05792f648df8ae659d1af92/qiv-command.example
I have an excel workbook in which there is data from multiple text files.
The text files are created in a .bat script.
I would like to refresh the workbook in the script right after creating the files.
Does anyone know a command that can do that?
Thanks!
For command line refresh (scheduled by Windows task scheduler) I ended up using this open source application: https://github.com/alapolloni/ExcelRefresh. Note that Excel needs to be installed on client for this to work.
You can specify what to update, for example "macros", "pivot tables", "Queries" or simply "all".
Together with this nice tool "WasFile" from https://www.horstmuc.de/wbat32.htm you can check the age to avoid unnecessary excel-refreshes.
For example, a batch file:
set file1="c:\Tmp\refreshMe.xlsx"
ECHO.
echo ----- %File1% -----------------------------
C:\Test\WasFile.exe %file1% modified not after today-1
if %errorlevel%==0 (echo TRUE: Older than
Goto Next1
)
if %errorlevel%==1 (
echo FALSE: Not older
goto Skip1
)
if %errorlevel%==255 (
Echo ERROR
goto Error
)
:Next1
Echo ### Update START ....
C:\test\ExcelRefresh.exe -d -a -f %file1%
Echo ### Update END ....
echo.
I don't think excel has CLI, but you can use VBS - there is example of importing data from excel spreadsheet using vbs: http://www.gregthatcher.com/Papers/VBScript/ExcelExtractScript.aspx but it's possible to do this in reverse direction too.
I prefer to edit in one large file rather than many independent files, but due to limitations in languages, source control, and the preference of team mates I need to output to many files.
What I'm looking for would recurse through all the files in a source directory and generate a single file to edit in VIM, with special file seperator markers. On save it would save the the changes to the correct file(s) ideally in a smart manner, based only on changes made.
Does something like this exist?
shar
Well, you could use shar(1), but it puts an X in front of each line that you will probably find annoying. (Shar came with my Mac but on my Linux systems you need to add a package.)
Shar is just, itself, a short shell script, so you could modify it easily enough to work without the X.
You might try copying /usr/bin/shar to /tmp and applying this diff with patch(1).
--- /usr/bin/shar 2009-07-13 22:26:18.000000000 -0700
+++ /tmp/shar2 2010-12-24 19:05:34.000000000 -0800
## -65,8 +65,8 ##
echo "mkdir -p $i > /dev/null 2>&1"
else
echo "echo x - $i"
- echo "sed 's/^X//' >$i << 'END-of-$i'"
- sed 's/^/X/' $i
+ echo "cat >$i << 'END-of-$i'"
+ cat $i
echo "END-of-$i"
fi
done
It reminds me of vimballs format. However, it's meant to expand files into the user runtimepath directory.
In other words, you can list all the files you want join and apply :MkVimBall (here is an example).
Then, for the extraction, you will have to momentarily (i.e. save and restore its value after the extraction) set &runtimepath to the root directory of your project before extracting with :so %.
You'll also have to play with various options like the &filetype, etc.
It's a dirty hack, but well ... it shall do the job.
Instead of dumping several files into one, processing this one and then separating stuff apart again, you could use bufdo or windo to repeat a command on all opened buffers: open the buffers to be processed, then cast the bufdo command and it will work on every opened file: http://vimdoc.sourceforge.net/htmldoc/windows.html#list-repeat