CrossOver Support - Community Forums

Important Information These are community forums and not official technical support. If you need official support: Contact Us

CrossOver Mac
Discussion about CrossOver Mac

The following comments are owned by whoever posted them. We are not responsible for them in any way.

Back to Threads Reply to Thread

How to start mac app from windows app passing command line arguments

Hello,

Say I'm using Total Commander file manager in Crossover. It runs fine on MacOs Ventura, M1 MacBook Pro 2020.
Now I want to select file in Total Commander and open it in native macOs Sublime Text app, is there a way to do it?
By now macOs home folder is mapped to y: drive in windows apps, so the minimal thing I'd like to accomplish is to somehow run any mac native application passing parameters from windows app running within Crossover.

KR, Anton

I have not found other solution except for implementing simple Python3 http server on MacOS side that invokes Sublime Text with passed path (it also replaces Windows-style paths with MacOS paths along the way):

import subprocess
import os

from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import parse_qs

class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        # Extract the query string parameters
        query_params = parse_qs(self.path[2:])

        if 'sublime' in query_params:
            file_to_edit = query_params['sublime'][0]
            file_to_edit = file_to_edit.replace('\\', '/')
            if 'z:/' in file_to_edit:
                file_to_edit = file_to_edit.replace('z:', '')
            elif 'y:/' in file_to_edit:
                file_to_edit = file_to_edit.replace('y:', os.path.expanduser('~'))

            subprocess.Popen(["/usr/bin/open", "-a", "/Applications/Sublime Text.app/Contents/MacOS/sublime_text", file_to_edit])

            self.send_response(200)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
        else:
            self.send_response(400)
            self.send_header('Content-type', 'text/plain')
            self.end_headers()
            self.wfile.write(b'Missing sublime parameter')

def run(server_class=HTTPServer, handler_class=RequestHandler, port=8000):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    print('Starting the server on http://localhost:{}/'.format(port))
    httpd.serve_forever()

if __name__ == '__main__':
    run()

Total Commander then invokes curl and passes path of the file at cursor:

rem contents of edit.bat
call y:\Workspaces\Various\curl-8.1.2_3-win32-mingw\bin\curl.exe -G -v http://localhost:8000/ --data-urlencode "sublime=%~1"

Please Note: This Forum is for non-application specific questions relating to installation/configuration of CrossOver. All application-specific posts to this Forum will be moved to their appropriate Compatibility Center Forum.

CrossOver Forums: the place to discuss running Windows applications on Mac and Linux

CodeWeavers or its third-party tools process personal data (e.g. browsing data or IP addresses) and use cookies or other identifiers, which are necessary for its functioning and required to achieve the purposes illustrated in our Privacy Policy. You accept the use of cookies or other identifiers by clicking the Acknowledge button.
Please Wait...
eyJjb3VudHJ5IjoiVVMiLCJsYW5nIjoiZW4iLCJjYXJ0IjowLCJ0enMiOi02LCJjZG4iOiJodHRwczpcL1wvbWVkaWEuY29kZXdlYXZlcnMuY29tXC9wdWJcL2Nyb3Nzb3Zlclwvd2Vic2l0ZSIsImNkbnRzIjoxNzMxNDM1MjAzLCJjc3JmX3Rva2VuIjoiaE01RWJLQzJ4QVphTnBXZCIsImdkcHIiOjB9