I don't remember what I did here
@@ -40,70 +40,28 @@ func RunShortcutsScript(at url: URL, arguments: [String], sendOutput: Bool = tru
}
}
- let code = """
- from rubicon.objc import ObjCClass
- from pyto import PyOutputHelper, Python
- from threading import Thread
- import sys
- import os
-
- path = str(Python.shared.currentWorkingDirectory)
- os.chdir(path)
-
- if path not in sys.path:
- sys.path.append(path)
-
- script = str(ObjCClass("Pyto.AppDelegate").shared.shortcutScript) # Get the script to run
-
- class ScriptThread(Thread):
- script_path = None
-
- def run(script, path):
- from console import __clear_mods__
- from pyto import PyOutputHelper, Python
- import runpy
- import sys
-
- error_message = None
-
- try:
- # Set arguments
- args = []
- for arg in Python.shared.args:
- args.append(str(arg))
-
- sys.argv = [sys.argv[0]]+args
-
- __clear_mods__()
- runpy.run_path(script)
- except SystemExit:
- pass
- except KeyboardInterrupt:
- pass
- except Exception as e:
- error_message = str(e)
-
- __clear_mods__()
-
- if path in sys.path:
- sys.path.remove(path)
-
- \(sendOutput ? "PyOutputHelper.sendOutputToShortcuts(error_message)" : "")
+ func run() {
+ DispatchQueue.global().async {
+ Python.pythonShared?.perform(#selector(PythonRuntime.runScript(_:)), with: Python.Script(path: url.path, debug: false, runREPL: false))
+ }
- thread = Thread(target=run, args=(script, path))
- thread.script_path = script
- thread.start()
- thread.join()
- """
+ _ = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { (timer) in
+ if !Python.shared.isScriptRunning(url.path) {
+ PyOutputHelper.sendOutputToShortcuts(nil)
+ timer.invalidate()
+ }
+ })
+ }
if !Python.shared.isSetup {
_ = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { (timer) in
if Python.shared.isSetup {
- Python.shared.run(code: code)
+ Thread.sleep(forTimeInterval: 0.5)
+ run()
timer.invalidate()
}
})
} else {
- Python.shared.run(code: code)
+ run()
}
}
