Skip to content

Commit

Permalink
mac compatibility, first mac release (buggy)
Browse files Browse the repository at this point in the history
  • Loading branch information
acrilique committed Dec 5, 2023
1 parent f6b0c24 commit 0ebd754
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ temp/
audio.mp3
audio.wav
.venv/
__pycache__/
__pycache__/
.DS_Store
59 changes: 39 additions & 20 deletions automarker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
if WINDOWS_SYSTEM:
subprocess.run([os.path.join(basedir, 'extension_installer_win.bat')])
else:
subprocess.run([os.path.join(basedir, 'extension_installer_mac.sh')])
script_path = os.path.join(basedir, 'extension_installer_mac.sh')
subprocess.run(['chmod', '+x', script_path])
subprocess.run([script_path])
os.makedirs(os.path.dirname(flag_path), exist_ok=True)
# Update the flag.txt file to indicate that the script has been executed, erasing old text
with open(flag_path, 'w') as flag_file:
Expand Down Expand Up @@ -113,9 +115,7 @@ def place_marks():

every = everyvar.get()
offset = offsetvar.get()
if (every > 1):
# Add only every x beats
beatsamplestoplace = beatsamples[offset::every]
beatsamplestoplace = beatsamples[offset::every]

info.set("Placing markers...")
root.update()
Expand Down Expand Up @@ -307,10 +307,10 @@ def exe_is_running(exe_name):
pids = _get_pids_from_name(exe_name)
if len(pids) == 1:
return True, pids[0]
if len(pids) > 1 and exe_name != AFTERFX_PROCESS_NAME:
raise OSError("More than one process matching name '{}' were found running (pid: {})".format(exe_name, pids))
if len(pids) > 1 and exe_name == AFTERFX_PROCESS_NAME:
if len(pids) > 1 and (exe_name == AFTERFX_PROCESS_NAME or exe_name == PREMIERE_PROCESS_NAME):
return True, pids[0]
if len(pids) > 1:
raise OSError("More than one process matching name '{}' were found running (pid: {})".format(exe_name, pids))
return False, None

def count_running_exe(exe_name):
Expand Down Expand Up @@ -345,7 +345,7 @@ def _get_pids_from_name(process_name):
else:
# use pgrep UNIX command to filter processes by name
try:
output = subprocess.check_output(["pgrep", process_name])
output = subprocess.check_output(["pgrep", "-f", process_name])
except subprocess.CalledProcessError: # pgrep seems to crash if the given name is not a running process...
return list()
# parse output lines
Expand All @@ -364,7 +364,10 @@ def __init__(self, aeVersion = "", returnFolder = ""):

# Try to find last AE version if value is not specified. Currently 24.0 is the last version.
if not len(self.aeVersion):
self.aeVersion = str(int(time.strftime("%Y")[2:]) + 1) + ".0"
if WINDOWS_SYSTEM:
self.aeVersion = str(int(time.strftime("%Y")[2:]) + 1) + ".0" # 24.0
else:# 2024
self.aeVersion = str(int(time.strftime("%Y")) + 1) # 2024

if WINDOWS_SYSTEM:
# Get the AE_ exe path from the registry.
Expand All @@ -375,15 +378,18 @@ def __init__(self, aeVersion = "", returnFolder = ""):

self.aeApp = _winreg.QueryValueEx(self.aeKey, 'InstallPath')[0] + 'AfterFX.exe'
else:
guess_path = "/Applications/Adobe After Effects" + self.aeVersion + "/Adobe After Effects " + self.aeVersion + ".app/Contents/MacOS/AfterFX"
guess_path = "/Applications/Adobe After Effects " + self.aeVersion + "/Adobe After Effects " + self.aeVersion + ".app/Contents/aerendercore.app/Contents/MacOS/aerendercore"
if os.path.exists(guess_path):
self.aeApp = guess_path
else:
print ("ERROR: Unable to find After Effects version " + self.aeVersion + " on this computer\nTo get correct version number please check https://en.wikipedia.org/wiki/Adobe_After_Effects\nFor example, \"After Effect CC 2019\" is version \"16.0\"")

# Get the path to the return file. Create it if it doesn't exist.
if not len(returnFolder):
returnFolder = os.path.join(tempfile.gettempdir(), "AutoMarker")
if WINDOWS_SYSTEM:
returnFolder = os.path.join(tempfile.gettempdir(), "AutoMarker")
else:
returnFolder = os.path.join(os.path.expanduser("~"), "Documents", "AutoMarker")
self.returnFile = os.path.join(returnFolder, "ae_temp_ret.txt")
if not os.path.exists(returnFolder):
os.mkdir(returnFolder)
Expand Down Expand Up @@ -412,9 +418,20 @@ def jsNewCommandGroup(self):
self.commands = []

def jsExecuteCommand(self):
target = [self.aeApp, "-ro", self.tempJsxFile]
if WINDOWS_SYSTEM:
target = [self.aeApp, "-ro", self.tempJsxFile]
else:
# Get the absolute path to the JSX file
jsx_file_path = os.path.abspath(self.tempJsxFile)

# Activate After Effects
subprocess.Popen(['osascript', '-e', f'tell application "Adobe After Effects {self.aeVersion}" to activate'])
time.sleep(0.1) # Wait for After Effects to activate

# Run the JSX script
target = ['osascript', '-e', f'tell application "Adobe After Effects {self.aeVersion}" to DoScriptFile "{jsx_file_path}"']
ret = subprocess.Popen(target)

def jsWriteDataOut(self, returnRequest):
""" An example of getting a return value"""
com = (
Expand Down Expand Up @@ -468,17 +485,17 @@ def jsAddMarkers(self, list):
jsxTodo = f"""
var item = app.project.activeItem;
var beats = {list};
if (app.project.activeItem instanceof CompItem) {{
var comp = app.project.activeItem;
}} else if (app.project.item(1) instanceof CompItem) {{
var comp = app.project.item(1);
}}
for (var i = 0; i < {list}.length; i++) {{
for (var i = 0; i < beats.length; i++) {{
var compMarker = new MarkerValue(String(i));
comp.markerProperty.setValueAtTime({list}[i], compMarker);
comp.markerProperty.setValueAtTime(beats[i], compMarker);
}}
"""
Expand Down Expand Up @@ -649,10 +666,10 @@ def clearAllMarkers(self):
p = pyaudio.PyAudio()
stream = None

if (is_afterfx_running()): aeApp = AE_JSInterface(returnFolder = os.path.join(tempfile.gettempdir(), "AutoMarker"))
if (is_afterfx_running()): aeApp = AE_JSInterface()
else: aeApp = None

if (is_premiere_running()): prApp = PR_JSInterface(returnFolder = os.path.join(tempfile.gettempdir(), "AutoMarker"))
if (is_premiere_running()): prApp = PR_JSInterface()
else: prApp = None

root = tk.Tk()
Expand All @@ -674,8 +691,10 @@ def clearAllMarkers(self):
root.geometry("+{}+{}".format(position_right, position_top))

style = ttk.Style()
style.theme_use(themename='xpnative')

if WINDOWS_SYSTEM:
style.theme_use(themename='xpnative')
else:
style.theme_use(themename='aqua')
mainframe = tk.Frame(root)
mainframe.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S))
root.columnconfigure(0, weight=1)
Expand Down
23 changes: 11 additions & 12 deletions automarker_mac.spec
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None

added_files = [
('icon.png', '.'),
('extension_installer_mac.sh', '.'),
Expand All @@ -22,12 +19,9 @@ a = Analysis(
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
Expand All @@ -42,18 +36,23 @@ exe = EXE(
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=universal2,
codesign_identity=None,
entitlements_file=None,
icon='icon.ico',
target_arch='x86_64',
codesign_identity='E9D38CA0B9FF902804EED51AAE0119CD2F0168E1',
entitlements_file='entitlements.plist',
icon='icon.png',
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='automarker',
)
app = BUNDLE(
coll,
name='automarker.app',
icon=None,
bundle_identifier=None,
)
13 changes: 13 additions & 0 deletions entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- These are required for binaries built by PyInstaller -->
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>

0 comments on commit 0ebd754

Please sign in to comment.