forked from seblavoie/sublime-extendscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtendScript_build.py
60 lines (44 loc) · 1.71 KB
/
ExtendScript_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import re
import sys
import subprocess
import json
print 'Building ExtendScript...'
script, currentPath, currentFileName, packages = sys.argv
buildFolder = packages+'/ExtendScript'
# Get default settings
with open(buildFolder+'/ExtendScript.sublime-settings') as settingsFile:
settings = json.load(settingsFile)
file_path = currentPath+'/'+currentFileName
if not os.path.exists(file_path):
print 'The file must be saved first to be built'
else:
with open(file_path, 'r') as file_handleFile:
file_string = file_handleFile.read().decode("utf-8-sig")
targetApp = ""
file_output = ""
for line in file_string.splitlines():
# Check if line includes target and
# then extract the words after the
# #target statment to variable targetApp
if re.match(r'.*#target', line) and targetApp == "":
regex = r'.*#target [\"\']?([^\"\';]*)[\"\']?;?'
targetApp = re.sub(regex, r'\1', line)
if targetApp == "":
targetApp = settings['default_app']
# Check target app
apps = ['aftereffects', 'photoshop', 'illustrator', 'indesign']
if targetApp in apps:
# Do script
appleScripts_path = packages+'/ExtendScript/Applescript'
appleScriptFile = appleScripts_path+'/run_'+targetApp+'.scpt'
subprocess.call(
'arch -x86_64 '
'osascript "'+appleScriptFile+'" "'+file_path+'"',
shell=True)
print 'Done'
else:
print 'Error: #Target: "'+targetApp+'" not recognised'
print 'Target must be one of:'
for app in apps:
print app