Tag Archives: Scripting

Batch conversion of SVG to PDF (updated)

Thanks to Runbgmn for the original instructions on batch conversion of svg to pdf. The instructions there are currently out of date, so here are an updated set of steps I found to batch converting svg to pdf with Inkscape.

Batch conversion of svg to pdf is very helpful. This is how it can be done under Mac OSX for free, no need to buy any software nor upload anything.

The Setup for Batch Conversion of SVG to PDF

  1. Get the free vector graphics program Inkscape and install it
  2. We’ll want to make inkscape available as a command in our terminal path. To do so, In a terminal execute create a link:
sudo ln -s /Applications/Inkscape.app/Contents/MacOS/inkscape /usr/local/bin/inkscape

3. Create a new file svg2pdf.sh with the following contents:

#!/bin/bash

# get path from command line
MYWD=$1

for file in *.svg
do
  echo $file $MYWD
  cat "$file" | inkscape --pipe --export-filename="${file%%.*}.pdf"
done

5. Make it executable:

chmod +x svg2pdf.sh

Usage

Run the script with the path to the folder filled with *.svg files to be batch converted to *.pdf.

Example:

bash svg2pdf.sh ~/Documents/folderOfSVGsToConvert

This will convert all svg files in the given directory into pdf.

Next you can use Adobe Acrobat, Preview, ghost script or many other programs to combine them into one single pdf file instead of multiple pdf files.

Combining Multiple PDFs into a Single PDF

Combining with Preview

The simplest way to combine multiple PDF files into a single one on Mac OSX is to using Preview.

A screenshot showing Preview application and how to open them thumbnails pane in the menu by opening View → Thumbnails or pressing Option + Command + 2. Which is handy for combining PDFs after batch conversion of svg to pdf files.
  1. Open the first page with Preview.
  2. Open thumbnails pane in the menu ViewThumbnails
  3. Drag and drop each PDF file into the thumbnail pane in the page order you’d like.

Combining with pdfunite

Install poppler, a PDF manipulation toolset.

brew install poppler

You’ll now have pdfunite command available, run it on your directory of PDFs to create a single PDF.

pdfunite *.pdf book.pdf

Speaking of Books

Looking for good engineering books? Take a look at my top rated engineering books I’ve found and recommend!

Script: Delayed Sleep / Hibernate

I often sleep or hibernate my computer when I’m finished for the night so I can resume where I left off in the morning.

Problem: I was listening to some music I figured I’d like to fall asleep to. However, I don’t allow my pc to fall asleep on its own. So how could I (for just this one time) set a delayed Hibernate?

With a batch command naturally!

timeout /t 1200 /nobreak && rundll32.exe powrprof.dll,SetSuspendState 0,1,0

There you have it. Timeout + Hibernate/Sleep. A silly solution for a silly problem.

Script: Unhide Network Drive Folders

There is an infection going around that hides all folders on a network drive and sets them as system folders. Here is a script I wrote that will remove the hidden and system attributes all folders/files in a directory you specify.
It uses the “attrib -h -s” and is not recursive into subdirectories.

For complete removal of the infection, naturally scan all machines. Remove any rouge autorun.ini files and rouge .exe files on the network drive.

Download: UnhideNetworkDriveFolders.v1.zip

I haven’t tested on all system setups and naturally comes with no warranty.

Update 3/22/2013

This script can only be run against a folder ( C:/Production/Shared ) not against an actual mapped drive ( S:/ ) at this time.

Update 3/27/2013

Here is a quick list of things to check regarding cleaning up the infection/worm.

  • Scan all PCs with Malwarebytes
    • Cleanup the the startup items
    • Cleanup and rouge exe files located
      • C:\User\%Username%
      • C:\User\%Username%\AppData
      • C:\User\%Username%\AppData\Roaming
    • Find proccess the infection is running under. Example:  jjhhgg.exe
  • Network drives, Flashdrives, External Harddrives
    • Delete all *.exe that mimic a folder and have a folders name
    • Delete autorun.inf
    • Delete x.mpg
    • Deltee anything else odd, rouge .exe files, photos files with .exe extentions
    • CMD Prompt, browse to the folder and run
      • attrib -h -s
      • Note this only unhides files, not folders.
    • CMD Prompt, browse to the folder and run
      • FOR /F "tokens=*" %i IN ('DIR /A:D /b') do attrib -h -s "%i"
      • Note this only unhides folders, make sure to have the quotation marks

 

Grouping Mailboxes with PowerShell

Here is a snip-it of PowerShell Code I am using to group and count the number of mailboxes on an Microsoft Exchange Server 2008 using CustomAttribute1.

On our server we have a unique ID stored in the CustomAttribute1 for mailboxes that belong to different groupings. For example in the CustomAttribute1 we store the company ID, in CustomAttribute2 we may store the service level they pay for. We found the need to keep a count of the number of mailboxes belonging to different companies.

$CountMembers = @{}
Get-Mailbox | foreach-object {$CountMembers[$_.CustomAttribute1]++}
$CountMembers

Naturally from here we can append the | Out-File Report.txt to save to a txt file. Ideally I would like to export to a csv, however this data format doesn’t support that. I may look further into this in the future.

We can use this method to group mailboxes by any common attribute actually. Say the count the number of mailboxes on each database using $_.Database