Open file with Adobe Captivate from command line - python

I am attempting to open an XML file with Adobe Captivate in my script using os.system(). Here is my code:
os.system("open /Applications/Adobe\ Captivate\ 9/Adobe\ Captivate.app/ \"flashcards_template_changed.xml\"")
It works fine the issue is with the opening screen on Adobe Captivate. When the program is run one of those 'New Document' windows pops up and asks you whether you want to start a new document, what kind of document, etc. Similar to Microsoft Word.
I was wondering if anyone had any experience bypassing this menu so the file would open. When I open Adobe Captivate and open my XML file it opens perfectly so I know it is in the right format.
Any help would be great! Thanks!

If Adobe Captivate is registered as the default application for handling XML files, then you can leave out the application name altogether:
os.system("open flashcards_template_changed.xml")
Otherwise, specify the application with the -a flag:
os.system("open -a captivate flashcards_template_changed.xml")
I don't know for certain that "captivate" is a recognized name for Adobe Captivate; I'm just guessing, and I don't have access to a suitable Mac to find out. If that doesn't work, you could probably use something very similar to what you had in your post:
os.system("open -a '/Applications/Adobe Captivate 9/Adobe Captivate.app' flashcards_template_changed.xml")

Related

Python script to open a file in Spotfire

So I want to add a button in my text area in Spotfire which will open an excel file (that is connected to my spotfire visualisation) or at least to a network folder with that file.
I believe I can write an ironpython script just to open that file and make changes. How will I do that?
Update:
After some googling I have tried to run a simple script smth like:
t=open('D:/data/folderA/folderB/file.xlsx','w')
To avoid problems with "/" or "\", I also tried importing os
import os
t=open('D:','data', 'folderA', 'folderB', 'file.xlsx', 'w')
Neither of these work.
For those who is still struggling to find the solution, it turned out to be simpler than I thought it would.
from System.Diagnostics import Process
Process.Start(r 'start c:\test\abc.xlsx')

How to gather data from a file and execute a Python file using it via right click?

This title is a bit confusing but let me explain. So say you have a file called test.txt. If you right click on it, it will most likely have a menu appear and will say stuff like "Open in Notepad". How can I get a python file to show in that menu so that it could say "Open in program.py" and the program would run and for example
print(data)
input()
Data being the contents of test.txt. Does anyone know if this is possible?
You need to edit the registry entries in Windows. See this to how.
You have to replace the path with your own script such as C:\\Program Files\\Something\\YourPythonScript %1
%1 represents the associated file name.
Edit: In your python script, you can use sys.argv in order to retrieve the file name of the associated file and process on it.
import sys
#Get selected file
filename = sys.argv[1]
you can use other programs to open your foo.py python code. but that program can't execute the code directly just by one click right. you have to open in program that can run python codes and run the code there.
hope this help you.

trying to open a file in its own program and wait until it closes

as a part of a python project i'm writing i need to open a file (could be all sorts of types) in its own program according to the registry (i need it to work on windows only) and wait until the program is closed so i can check if the file was changed (or edited in the program).
i read a lot of other questions about this subject, yet i can find the solution.
i tried using subproccess.Popen, call or check_all as well as os.startfile and psutil for checking the pid of the procces.
EDIT: all the files are located in the same folder with the script that opens them. i can open the files yet i cant get it to wait until it closes. it will wait only when the program is notepad.exe
EDIT 2: so far i used this code:
doc = subprocess.Popen(["start", "/WAIT", file_path], shell=True)
doc.wait()
this code opens any file i ask it to but the doc.wait() will wait only when notepad.exe is the opened program. for example, i tried opening a .docx file with microsoft word and it opened but didnt wait for me to close the document.
i cant run it without shell=True because when i do it throws a "can find file" error.
thanks for any answers,
dor

Open file with its default program via python

I need to implement the user guide of my program and I was thinking on putting a button that opens the pdf, like if its double clicked on Windows Explorer.
But I've tried with os.popen(myfile) and open(myfile) and the interpreter open it in python, so I can print and it prints me the info of the object <_io.TextIOWrapper name='userguide.pdf' mode='r' encoding'cp1252' and what I need is to open it with its native application to avoid embed the pdf into the program.
Any way to do this?
Thanks
To open it in the default application for that file type:
subprocess.Popen([file],shell=True)
Considering that you are implementing a user guide, you may want to open it in a web browser.
import webbrowser
webbrowser.open_new(r'file://C:\path\to\file.pdf')

Opening an image file using Sikuli/Jython without clicking

I'm writing a script that saves an image file to the desktop (so "image.JPG"). After doing that, I want to open the image file so that it is displayed on the screen. I've been trying to use subprocess (which I have no experience with), but can't seem to get it to work.
import subprocess
subprocess.Popen("C:/Users/first.last/Desktop/image.JPG")
However, that results in the following error:
[error] OSError ( Cannot run program "C:/Users/sean.sheehan/Desktop/image.JPG" (in directory "C:\SikuliX"): CreateProcess error=193, %1 is not a valid Win32 application )
I'm assuming this is because it is a file rather than an application (maybe I have to open an application that allows you to view an image?)
So, is there a way to open an image file in sikuli/jython/python without having to double click it with sikuli? I'd also prefer not to download any additional packages.
Thanks.
If it was a normal Python, you would use os.startfile():
Start a file with its associated application.
import os
filename = "C:/Users/first.last/Desktop/image.JPG"
os.startfile(filename)
But, the problem is that the are things (C-based functionality) that exist in Python, but are missing in Jython. And os.startfile() is one of these things.
subprocess.call() should work in Jython:
import subprocess
filename = "C:/Users/first.last/Desktop/image.JPG"
subprocess.call('start ' + filename)
Also see more options at:
Open document with default application in Python

Categories

Resources