Last active
December 9, 2016 17:53
-
-
Save dan-passaro/91888d2b3c36f8ad3f7a6c68817015ac to your computer and use it in GitHub Desktop.
Convert spreadsheets to CSV using LibreOffice Calc, even with a window open
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use 5.014; | |
use Cwd; | |
use File::Temp (); | |
use File::Spec; | |
my $file = $ARGV[0] or die "Provide a file to convert.\n"; | |
my $tempdir = File::Temp->newdir; | |
my $profile = File::Spec->catdir($tempdir, "profile"); | |
# Use a temporary profile to allow the command to run even if there's another | |
# LibreOffice running (e.g. a GUI window). See: | |
# <https://bugs.documentfoundation.org/show_bug.cgi?id=37531#c24> | |
my $libre_profile = "-env:UserInstallation=file://$profile"; | |
my $cmd = "libreoffice --convert-to csv --outdir '${\cwd()}' '$libre_profile' '$file'"; | |
say $cmd; | |
exit system($cmd); # Don't use exec, or else tempdir won't be cleaned up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment