Skip to content

Commit b62c5a5

Browse files
committed
added makefile and new export script
1 parent 6785f91 commit b62c5a5

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
# get paths and stuff
3+
# defines
4+
# EXPORTSCRIPT
5+
# SOURCEPATH
6+
# EXPORTPATH
7+
include make-conf-local
8+
EXPORTARGS=scale=2 resolution=2 scope="entire document"
9+
42DPI=scale=1 resolution=0.58 scope="entire document"
10+
PDFJOIN='/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py'
11+
12+
# usage: ./ogexport.js <source> <format> <target> <property_1=value_1>...<property_n>=<value_n>
13+
# e.g. ./ogexport.js /Users/beb/dev/ogtool/JXA/test-data/test-data.graffle PNG /Users/beb/tmp/fat scale=2 resolution=2
14+
# full path to document and export is required because this JS stuff sucks, define them in make-conf-local
15+
# transparent background:
16+
# resolution=1.94444441795 scale=1.0 drawsbackground=0 scope="entire document"
17+
# SVG: scope="entire document"
18+
19+
20+
# $(call export_language,src,en-tmp,PNG)
21+
define export_language
22+
ogexport.js $(SOURCEPATH)/$(1)/workflow-and-value.graffle $(3) $(EXPORTPATH)/$(2)/workflow-and-value scale=2 resolution=2 scope="entire document"
23+
endef
24+
25+
test:
26+
# 1. Build small png (625 x 470 px)
27+
# (used for documentation in the repo and for s3 website)
28+
29+
-mkdir tmp/42dpi
30+
ogexport.js $(SOURCEPATH)/s3-delegation-canvas.graffle PNG $(EXPORTPATH)/42dpi/s3-delegation-canvas $(42DPI)
31+
mv tmp/42dpi/s3-delegation-canvas/s3-delegation-canvas-with-guide.png docs/img/s3-delegation-canvas-sm.png
32+
ogexport.js $(SOURCEPATH)/s3-organization-canvas.graffle PNG $(EXPORTPATH)/42dpi/s3-organization-canvas $(42DPI)
33+
mv tmp/42dpi/s3-organization-canvas/s3-organization-canvas-with-guide.png docs/img/s3-organization-canvas-sm.png
34+
ogexport.js $(SOURCEPATH)/s3-team-canvas.graffle PNG $(EXPORTPATH)/42dpi/s3-team-canvas $(42DPI)
35+
mv tmp/42dpi/s3-team-canvas/s3-team-canvas-with-guide.png docs/img/s3-team-canvas-sm.png
36+
37+
38+
site:
39+
cd docs; bundle exec jekyll build
40+
41+
42+
xprt-en:
43+
-mkdir png/en-tmp
44+
$(call export_language,src,en-tmp,PNG)
45+
46+
47+
xprt-svg:
48+
-mkdir png/en-svg
49+
$(call export_language,src,en-svg,SVG)
50+

ogexport.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env osascript -l JavaScript
2+
/*
3+
A JXA script for exporting OmniGraffle documents from the commandline
4+
5+
usage: ./ogexport.js <source> <format> <target> <property_1=value_1>...<property_n>=<value_n>
6+
7+
e.g. ./ogexport.js /Users/beb/dev/ogtool/JXA/test-data/test-data.graffle PNG /Users/beb/tmp/fat scale=2 resolution=3
8+
9+
although scope is not really a "property", it can be still handed in as if it were one.
10+
11+
for some strange reaseon the full path to the og document and for the target is required
12+
13+
Accessing and setting app properties:
14+
OmniGraffle.documents[0].name()
15+
OmniGraffle.documents[0].canvases[0].name.set("foo")
16+
OmniGraffle.currentExportSettings.exportScale()
17+
OmniGraffle.currentExportSettings.areaType()
18+
OmniGraffle.currentExportSettings.areaType.get()
19+
20+
*/
21+
22+
function run (argv) { // eslint-disable-line no-unused-vars
23+
var parameters = setParameters(argv)
24+
25+
// open app if not already open
26+
var appOpened = false
27+
if (!Application('OmniGraffle').running()) { // eslint-disable-line no-undef
28+
ObjC.import('AppKit') // eslint-disable-line no-undef
29+
$.NSWorkspace.sharedWorkspace.launchApplication('/Applications/OmniGraffle.app') // eslint-disable-line no-undef
30+
// console.log("opening app")
31+
appOpened = true
32+
}
33+
34+
var OmniGraffle = Application('OmniGraffle') // eslint-disable-line no-undef
35+
OmniGraffle.includeStandardAdditions = true
36+
// console.log("opening " + parameters.source)
37+
var doc = OmniGraffle.open(parameters.source)
38+
39+
// doc.export({as:"PNG", scope:"entire document", to:Path("/Users/beb/tmp/"), withProperties: {scale:1.0, resolution:1.94444441795}})
40+
doc.export({ as: parameters.format,
41+
scope: parameters.scope,
42+
to: Path(parameters.target), // eslint-disable-line no-undef
43+
withProperties: parameters.properties })
44+
45+
doc.close()
46+
if (appOpened) {
47+
// close app if it was not already open
48+
OmniGraffle.close()
49+
}
50+
console.log('...done')
51+
}
52+
53+
function exportName (filename) {
54+
if (filename.substr(-8, 8) === '.graffle') {
55+
return filename.substr(0, filename.length - 8)
56+
} else {
57+
return filename.concat('.out')
58+
}
59+
}
60+
61+
function setParameters (argv) {
62+
// parse commandline parameters, set default properties
63+
64+
// console.log(JSON.stringify(argv))
65+
var source = argv[0]
66+
var format = argv[1]
67+
var target = argv[2]
68+
var myproperties = argv.slice(3)
69+
console.log('Exporting OmniGraffle document -------------------------------------------')
70+
console.log('Source: ' + source)
71+
console.log('Format: ' + format)
72+
console.log('Target: ' + target)
73+
console.log('Properties: ' + JSON.stringify(myproperties))
74+
75+
// set defaults for properties
76+
var properties = {
77+
scale: 1.0,
78+
resolution: 1.94444441795,
79+
borderamount: 0.0,
80+
copylinkedimages: true,
81+
drawsbackground: true, // true for transparent
82+
readonly: false,
83+
htmlimagetype: 'PNG',
84+
includeborder: false,
85+
includenonprintinglayers: false,
86+
useartboards: false,
87+
scope: 'entire document'
88+
}
89+
90+
myproperties.forEach(function (element) {
91+
var res = element.split('=')
92+
properties[res[0]] = res[1]
93+
})
94+
95+
var parameters = {
96+
source: source,
97+
format: format,
98+
scope: properties.scope,
99+
target: target,
100+
properties: properties
101+
}
102+
103+
var validAreaTypes = ['all graphics', 'current canvas', 'entire document', 'selected graphics']
104+
var validFormats = ['PNG', 'JPG', 'GIF', 'BMP', 'TIFF', 'PSD', 'OOutline', 'Graffle', 'Visio', 'PDF', 'EPS', 'SVG', 'HTML']
105+
106+
if (!validAreaTypes.includes(parameters.scope)) {
107+
throw new Error(`"${parameters.scope}"" is not a valid scope`)
108+
}
109+
if (!validFormats.includes(parameters.format)) {
110+
throw new Error(`"${parameters.format}" is not a valid format`)
111+
}
112+
return parameters
113+
}

0 commit comments

Comments
 (0)