From db7bd28d2be72963c00c085b244e9ed6d768a77f Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 7 Jan 2011 13:26:44 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20Default=20Bundle:=20Copy=20as=20JSO?= =?UTF-8?q?N=20=E2=80=A2=20after=20selecting=20a=20Bundle=20in=20the=20Bun?= =?UTF-8?q?dle=20Editor=20jump=20to=20the=20beginning=20of=20the=20command?= =?UTF-8?q?=20in=20order=20to=20avoid=20unstable=20display=20issue=20insid?= =?UTF-8?q?e=20the=20command=20textview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CopyAsJSON.spBundle/command.plist | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist (limited to 'SharedSupport/Default Bundles') diff --git a/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist new file mode 100644 index 00000000..86bf998a --- /dev/null +++ b/SharedSupport/Default Bundles/CopyAsJSON.spBundle/command.plist @@ -0,0 +1,129 @@ + + + + + author + Hans-Jörg Bibiko + category + Copy + command + cat | perl -e ' + +# read first line to get the column names (header) +$firstLine = <>; + +# bail if nothing could read +if(!defined($firstLine)) { + exit 0; +} + +# store the column names +chomp($firstLine); +$firstLine =~ s/\"/\\\"/g; # escape " +@header = split(/\t/, $firstLine); + +$h_cnt = $#header; # number of columns + +# get the column definitions +open(META, $ENV{"SP_BUNDLE_INPUT_TABLE_METADATA"}) or die $!; +@meta = (); +while(<META>) { + chomp(); + my @arr = split(/\t/); + push @meta, \@arr; +} +close(META); + +print "{\n\t\"data\":\n\t[\n"; + +# read row data of each selected row +$rowData=<>; +while($rowData) { + + print "\t\t{\n"; + + # remove line ending + chomp($rowData); + + # escape " + $rowData=~s/\"/\\\"/g; + + # split column data which are tab-delimited + @data = split(/\t/, $rowData); + for($i=0; $i<=$h_cnt; $i++) { + + # re-escape \t and \n + $cellData = $data[$i]; + $cellData =~ s/↵/\n/g; + $cellData =~ s/⇥/\t/g; + + print "\t\t\t\"$header[$i]\": "; + + # check for data types + if($cellData eq "NULL") { + print "null"; + } + elsif($meta[$i]->[1] eq "integer" || $meta[$i]->[1] eq "float") { + print "$cellData"; + } else { + print "\"$cellData\""; + } + + # suppress last , + if($i<$h_cnt) { + print ","; + } + + print "\n"; + + } + + print "\t\t}"; + + # get next row + $rowData=<>; + + # suppress last , + if($rowData) { + print ","; + } + + print "\n"; +} + +print "\t]\n}\n"; + +' | __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbcopy + contact + znvy@ovovxb.qr + description + Copies the selected rows excluding any BLOB data in a data table JSON formatted into the pasteboard. + +Version 1.0 + input + selectedtablerowsastab + internalKeyEquivalent + + characters + C + keyCode + 8 + modifierFlags + 262144 + + keyEquivalent + ^c + name + Copy as JSON + output + none + scope + datatable + tooltip + Copies the selected rows excluding any BLOB data JSON formatted into the pasteboard + uuid + CBB8B7A7-5AB9-4F4C-A404-D99CA9521337 + isDefaultBundle + + + -- cgit v1.2.3