How do I write a batch process on the Mac for pdf2swf, I want to convert all pdfs in a folder into swf. But pdf2swf doesn't have a option to convert a folder of pdfs to swfs, you have to do it one at a time. I'm not sure how if I should use a Apple script or a Shell script, either one I'm not sure how to get or assign a file name variable.
pdf2swf file_name_variable.pdf -o file_name_variable.swf -T 9 -f
Thanks
Open up Terminal and do something like this:
$ for f in `find /path/to/my/pdf/directory -name \*.pdf` ; do
> echo "Processing $f..."
> pdf2swf $f -o ${f/.pdf/.swf} -T 9 -f
> done
Related
I want to create a script from terminal to be used like this one:
ddmg StartingDirectory
that will create into the StartingDirectory a dmg file for each subdirectory present.
Example:
\StartingDirectory
\MDT1D01
\MDT1D02
\MDT1D03
\MDT1DN
command should run for each subdirectory MDT1D0 (1..N)
and create a .dmg for each, with VolumeName and FileName as the name of the same subdirectory (that is MDT1D01 f.i.).
(VolumeName is the name that appears at the left side of the Finder when you open the dmg).
I already know that the command to create dmg is:
hdiutil create -volname VolumeName -srcfolder /path/to/the/folder/you/want/to/create -ov -format UDZO FileName.dmg
and this is working because I tested it.
I've already tried to create a personal command named dmg, in this way:
dmg(){
hdiutil create -volname “$1” -srcfolder “$2” -ov -format UDZO “$3.dmg”
}
that should be used in this way:
dmg VolumeName source/directory/path FileName
but it doesn't seem to work and I don't understand why.
In addition I found a template to create scripts (this is working but it says I need to install xtools to work properly, I suppose because of the git command that I don't need right now):
#!/bin/bash
#Use set -x if you want to echo each command while getting executed
#set -x
#Save current directory so we can restore it later
cur=$PWD
#Save command line arguments so functions can access it
args=("$#")
#Put your code in this function
#To access command line arguments use syntax ${args[1]} etc
function dir_command {
#This example command implements doing git status for folder
cd $1
echo "$(tput setaf 2)$1$(tput sgr 0)"
git tag -a ${args[0]} -m "${args[1]}"
git push --tags
cd ..
}
#This loop will go to each immediate child and execute dir_command
find . -maxdepth 1 -type d \( ! -name . \) | while read dir; do
dir_command "$dir/"
done
#This example loop only loops through give set of folders
declare -a dirs=("dir1" "dir2" "dir3")
for dir in "${dirs[#]}"; do
dir_command "$dir/"
done
#Restore the folder
cd "$cur"
With these info, could you help me to create the script I need?
I'm a newbie, so please be quite specific :)
Thanks a lot in advance!
I found a way to do that.
This is the code:
#!/bin/bash
#Use set -x if you want to echo each command while getting executed
#set -x
#Save current directory so we can restore it later
cur=$PWD
#Save command line arguments so functions can access it
args=("$#")
#Put your code in this function
#This loop will go to each immediate child and execute hdiutil
find . -depth 1 -type d | cut -c 3- | while read dir; do
hdiutil create -volname $dir -srcfolder $dir -format UDZO $dir.dmg
done
#Restore the folder
cd "$cur"
Note that I've cut the "-ov" option to hdiutil, so it's not going to overwrite an existing dmg.
It's very useful because if you have a lot of subdirectories, it could happen that you get errors at some point (for instance I got the "resource busy" error), and in this way you can simply relaunch the command without worrying about what directory has got the error.
Just tested and it's working flawlessly. 5 hours it's creating dmgs right now :)
I'm trying to make this bash script but get this: Error reading *.docx. The file doesn’t exist
Here's the script:
#!/bin/bash
textutil -convert txt *.docx
cat *.txt | wc -w
I'm currently running it from the folder but I'd like to make it a global script I can just call from any current folder.
If you want to make it available on your whole system you need to move it to a bin location like so
chmod a+rx yourscript.sh && sudo mv yourscript.sh /usr/local/bin/yourscript
then you can use it like a normal script in any folder
I use "MacOS X Yosemite (10.10.4)"
I've converted video mts files to mov files using QuickTime, but the new file created doesn't preserve original Creation Date.
fileA.mts --> Creation Date: 07/02/2010 10:51
fileA_converted.mov --> Creation Date: Today 8:35
I'd like to change the Creation Date attribute of several files, using the date of the original files. I know I can do this by using Terminal "Touch" command in order to this:
touch -r fileA.mts fileA_converted.mov
touch -r fileB.mts fileB_converted.mov
As I have more than 200 files to change Creation Date, is it possible to automate this using automator Script Shell action, or any other way?
Like this in the bash shell - which is what you get in Terminal (untested):
#!/bin/bash
for orig in *.mts; do
# Generate new name from old one
new="${orig/.mts/_converted.mov}"
echo touch -r "$orig" "$new"
done
Save the above in a file called doDates and then type this in the Terminal
chmod +x doDates # make the script executable
./doDates # run the script
Sample output
touch -r Freddy Frog.mts Freddy Frog_converted.mov
touch -r fileA.mts fileA_converted.mov
At the moment it does nothing, but run it, see if you like what it says, and then remove the word echo and run it again if all looks ok.
Execute below command when we have all original and converted files in same folder
ls | grep ".mts" | awk -F. '{print $0" "$1"_converted.mov"}' | xargs touch -r
when we have different folder run below command on path where .mts files are present and add absolute path before $1 just like I have added /home/convertedfiles/
ls | grep ".mts" | awk -F. '{print $0" /home/convertedfiles/"$1"_converted.mov"}' | xargs touch -r
--Bash 4.1.17 (running with Cygwin)
Hello, I am trying to pass the date into the --suffix option on the move (mv) command. I am able to pass in a simple string (like my name) but unable to pass in the date. If you run the script below you will see that the mv command with the suffix="$var" works but suffix="$now" does not.
#!/bin/bash
dir="your directory goes here"
now="$(date "+%m/%d/%y")"
var="_CARL!!!"
echo "$now"
echo "$var"
cd "$dir"
touch test.txt
# error if already exists
mkdir ./stack_question
touch ./stack_question/test.txt
mv -b --suffix="$var" test.txt ./stack_question/
The idea is that if test.txt already exists when trying to move the file, the file will have a suffix appended to it. So if you run this script with:
--suffix="$var"
you will see that the stack_question directory contains two files:
test.txt & test.txt_CARL!!!
But, if you run this script with:
--suffix="$now"
you will see that in the stack_question directory only contains:
test.txt
Any help on this would be greatly appreciated!
It is because you have embedded / in your date format try
now="$(date +%m_%d_%y)"
How can I run the vim command ":retab" using a shell script to all the files in the current dir?
I found something that could help you
for F in *.{c,h}pp ; do vim -c ":retab" -c ":wq" "$F" ; done
This should do what you'd like ;) maybe you'll need to change the for loop condition to your needs