Building useable program in Terminal/Applescript for extracting XLSX to CSV - applescript

I'm looking for a way to automate XLSX to CSV conversion. Ideally, I would also like to add column names that are not yet in the XLSX.
For now, I'm using CSVkit/In2CSV. This works, but I still have to enter the name of the file manually. In terminal, I now do this:
in2csv /Users/file.xslx -f xlsx -I > file.csv
I would like to be able to automate this, so that when I open the script, it asks me for the location of the file (or I just drag the file to the script), and then it automatically converts. I have looked into AppleScript, but can't really seem to figure it out, must probably be very easy. How can I automate this? I'm on a Mac.

Related

Fill an existing LibreOffice document with values from the command line

I run a bash script which generates a PDF at the end of a billing run. I used to do that with LaTeX but the users ask for a more MS Office like solution. So I'm thinking of using a LibreOffice document and use LibreOffice on the command line to generate the PDF. That works. But I have no idea how to inject the values I need to change (e.g. the address and the billing information) into that document before I can generate a PDF.
Let's assume the example.odt document contains this text:
Dear $fist_name,
you own us $amount USD.
Regards
xyz
Since example.odt is not really easy to edit from a Bash script I'm searching for an other way to inject values for $first_name and $amount.
What is the best way to do this?
The LibreOffice file is a zip archive which can be unzipped with
unzip old.odt -d example
cd example
The content of the file is in the file content.xml. There is can be changed with sed or any other tool. After that the .odt file has to be created again:
zip -r ../new.odt .
After that the PDF can be created with this command (the path is from OS X):
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless
--convert-to pdf:writer_pdf_Export --outdir ~/Desktop/ ~/Desktop/new.odt

How to create a batch file in Mac?

I need to find a solution at work to backup specific folders daily, hopefully to a RAR or ZIP file.
If it was on PC, I would have done it already. But I don't have any idea to how to approach it on a Mac.
What I basically want to achieve is an automated task, that can be run with an executable, that does:
compress a specific directory (/Volumes/Audio/Shoko) to a rar or zip file.
(in the zip file exclude all *.wav files in all sub Directories and a directory names "Videos").
move It to a network share (/Volumes/Post Shared/Backup From Sound).
(or compress directly to this folder).
automate the file name of the Zip file with dynamic date and time (so no duplicate file names).
Shutdown Mac when finished.
I want to say again, I don't usually use Mac, so things like what kind of file to open for the script, and stuff like that is not trivial for me, yet.
I have tried to put Mark's bash lines (from the first answer, below) in a txt file and executed it, but it had errors and didn't work.
I also tried to use Automator, but it's too plain, no advanced options.
How can I accomplish this?
I would love a working example :)
Thank You,
Dave
You can just make a bash script that does the backup and then you can either double-click it or run it on a schedule. I don't know your paths and/or tools of choice, but some thing along these lines:
#!/bin/bash
FILENAME=`date +"/Volumes/path/to/network/share/Backup/%Y-%m-%d.tgz"`
cd /directory/to/backup || exit 1
tar -cvz "$FILENAME" .
You can save that on your Desktop as backup and then go in Terminal and type:
chmod +x ~/Desktop/backup
to make it executable. Then you can just double click on it - obviously after changing the paths to reflect what you want to backup and where to.
Also, you may prefer to use some other tools - such as rsync but the method is the same.

Import Query into Windows Grep tool

I've been using grepWin,
And I would like to somehow perform a series of queries for pdf links within .html files.
Thus far with the tool I have been using I just input each individual PDF name and copy the file paths of each reference.
This works fine but I have several hundred specific PDFs I need to find the references for,
And I was wondering if this was possible by using Cygwin or some other cmdline like Findstr to pipe a textfile of links to PDF's which I am searching.
I will give an example:
Spring-Summer.pdf
I would copy all of the paths to which the listed file is linked to within html files.
I then need that copied next to it, or in its own column within csv.
I'm not sure if it's at all probable anyone has asked this before. Currently I'm filling out a spreadsheet of links to these files for a website..
In Linux the following command will find all the html files which contain the specified string:
grep -Rl "Spring-Summer.pdf" <some root folder>
The -R option is to search recursively, and -l is to display just the file name without content.
The same should work on Cygwin.

Modify text file in VMDK

I need to modify a text file in the file system of a VMDK file for a deployable OVA file. I have seen that it is possible to find the string (a test string in the text file needing modification) and replace it in the VMDK using sed, however whenever I try to replace it, it seems to work, but then nothing actually changes in the file. Here is what I have tried:
sed -i 's/oldstring/newstring/g' file.vmdk
The sha1sum before and after are identical telling me the file has not been modified. Something gets goofed up though because I can no longer start the VM of that VMDK (its ok, its a test).
Does anyone have any programmatic suggestions here. I will be doing all of this in bash. If no one can suggest anything, I will move this question to servar fault or SuperUser and ask if anyone knows how to mount the VMDK (Without VMware-tools!!!) then edit the file directly with sed or via some other means.
Perhaps there is some way of doing a binary search or something for the string to replace.

Using sed to find a string in one file and replace with text in another file in Xcode

shell: /bin/tcsh
I'm attempting to search for a string in a Cocos2D tmx file and replace it with text from another file.
Before the touch commands in Run Script, I have the following:
sed -i '' 's{<tileset firstgid="1.*<layer name="background"{Resources/maps_sideScrolling/tileProperties.txt{g' Resources/maps_sideScrolling/ruinsItemCave2.tmx;
I'm fairly certain the file ruinsItemCave2.tmx is found, because if I change the file path I get an error when I build the project. As of now, ruinsItemCave2.tmx is not affected in any way.
Eventually I will want to change ruinsItemCave2 to a wildcard filename so it affects every file name, though I'm not sure how to write Resources/maps_sideScrolling/*.tmx the proper way.
I also know that without even writing a file path of tileProperties.txt, but just writing "test" does nothing to my ruinsItemCave2 file, so I can't even get that far as of now. Does it have to do with using tcsh?

Resources