I'm not at all sure that what I need is possible with the tools that I have, but I thought I'd ask.
I have the following Python script (technically IronPython, but I don't fully understand the difference), that I pulled from a blog and modified for my purposes:
import datetime
from System.IO import StreamWriter
from Spotfire.Dxp.Application.Visuals import TablePlot
tempFolder = "C:\\Spotfire Exports\\"
tempFilename = "Data.txt"
writer = StreamWriter(tempFolder + tempFilename)
vTable.As[TablePlot]().ExportText(writer)
print tempFolder + tempFilename
The script itself works perfectly fine, but the problem is that I need to be able to make this run automatically at a certain time of day, i.e., I need the *.txt file to be updated in the morning before I get to my desk. (The project pulls from a database that isn't accessible through MS Access.)
Although the script runs fine, I have to manually push the button to activate it. I can't seem to find any way to have the script run on file open (so that I can use Windows Task Scheduler) to make it run when the file is opened.
Does anybody know if there's a way to do this?
Bear in mind, I do not have Visual Studio available to me. I already tried Visual Studio Express, and it doesn't seem to be able to access the Spotfire SDK macros.
You can utilize JavaScript to click a button on load and have that button be your python script. Like so:
window.onload = function callButtonClickEvent(){
document.getElementById('YOUR_SPOTFIRE_CONTROL_ID').click();
}
By clicking "edit HTML" in the text box you're using you can see the ID spotfire has assigned your button. The above code will click that button once upon loading.
If you do not want your button to be shown to end users (if applicable) then you can put it inside a hidden div or span:
<span style='display:none'><SpotfireControl id="YOUR_SPOTFIRE_CONTROL_ID" /></span>
Then once this is setup it should run your script when opened as per your windows task scheduler as you desired.
Let me know if you have any questions regarding implementation.
Related
So, the shop where I work use Excel 4.0 for all its inventory management and orders.
Since the guy before me left without explaining anything, I inherited an old system that works, but is... eh.
The bosses don't want to change to a new Excel nor another program, so I must do what I can with what I have.
Now, I've made a script in python 2.5.4 (this version is needed because the newer versions won't work on the Windows 98 computer they use...) to automate some processes that would be impossible with Excel 4.0 macros, and the script works perfectly for what I need.
But since the bosses want to "only work with Excel", and won't want to go outside of Excel and click the script icon to start it (or, heaven forbid, open cmd and start it manually), I would need to put a button in Excel to start the script.
I've tried to sift through the macros available, but except perhaps "Initiate" (which I don't wholly understand as of now), I can't think of a macro to interact with the script, and haven't found much help with what's available online...
SO, could anyone please help me in making the macro for the button? The only thing the button would need to do is to start the python script, there's no other interactions needed, the rest is done by the script.
Like, the script "foo.py" is in the same folder as "bar.xls", and I only need a button in "bar.xls" to launch "foo.py".
Thanks.
Okay, I found a roundabout way, so I'm gonna share it with y'all.
MacroName
=LAUNCH("cmd",1)
=SEND.KEYS("foo.py~";TRUE)
=SEND.KEYS("exit~")
=RETURN()
It opens a cmd instance, show it for a split second (can't use SEND.KEYS without it being the active app), writes the name of the python script and presses enter, before quitting.
I would like if it didn't need to show the cmd window, but it works for now. Perhaps there'll be another way, but if anyone else wanna do what I did, it does work.
You probably need to get the book out - Excel 4 came with one book called the Function Reference which listed all the commands available.
Commands that we used back in the day were:
EXEC: starts another program
EXECUTE: runs commands in another program called by Initiate
INITIATE: sets a channel to a program
SEND.KEYS: sends keystrokes to a program (we used to send data to a slow server this way...)
Not sure what will be on the web for Excel macro 4, it was retired as vba came out and Excel moved over...
I still use my copy of the book, but it would be worth finding, although the help should list the commands as well. I just used the book as I had macros running...
I'm fairly new to python, and I am trying to run the code I wrote when I right click the playback range windows in the timeline of maya (where you type your min or max range) . I managed to find ways to run scripts within the attribute editor / timeline / shelf items, but I cant seem to figure out how to interact with Maya's UI... Even typing a new value in there doesn't update the script editor, so I don't really have a lead on where to go. Any help would be fantastic!
you basically want to add a menu item in the timeslider ?. You can get all maya widget using OpenMayaUI.MQtUtil and here is a full repo which modify timeline control https://github.com/robertjoosten/maya-timeline-marker
Everything Maya does when using the UI logs data in the script editor.
Many items in the log are suppressed though as it would spam the log.
To enable it, activate Echo all commands (can be found in script editor under History), then clear the script editor and perform the action you want logged.
You will find that Maya executes a lot of mel script functions, which you can all find in the maya install directory under [MAYA_INSTALL_DIR]/scripts/startup and [MAYA_INSTALL_DIR]/scripts/others
To find the essential function you will have to search a little through the log.
Once you got a mel function you want to look for, I recommend using a find in files search function like the one in Notepad++, to find the corresponding .mel file in which the global proc is defined.
Also note that UI element names that are logged in script editor may have a different name the next time you start maya. So you will have to add functionality to search for the correct UI element name.
The Maya mel scripts are a good resource to find out all sorts of things about how the UI works, including contextual marking menus and the commands of tool windows.
I am building a datalogger for a group of PV inverters using Raspberry Pi and am using two python scripts to collect the data over two separate communication protocols. I need to change two variables in each script if I move from one site to another - the first and the last inverter id for the new site.
I want to make this change user friendly such that a new user does not have to open the python script to change the values. So I want to have an executable program in linux environment (which may have an icon on the Pi desktop) which the user can open and it will prompt to specify first and last inverter id and transfers this change to python script. If this is too complicated to achieve for this task, maybe a simple command for the terminal window which will prompt the same changes??
I hope the task is sufficiently explained. I am not a programmer by trade and am doing this project as a hobby, so please forgive me if I am ignoring something obvious :|
Just posting a successful update for this query. The desktop configuration file method was the simplest and it worked. I wrote the following in the .desktop file
[Desktop Entry]
Version=1.0
Name= ProgramName
Comment= my comment
Exec=sudo python /usr/share/app/app.py
Icon=/usr/share/pixmaps/geany.xpm
Path=/usr/local/lib/python2.7
Terminal=true
Type=Application
Categories=Utility;Application;
I added the "python" bit to the Exec line and hence did not have to write a she-bang line in the script. Also the Terminal option had to made True since I needed a prompt for the user to enter a value.
Hope this helps somebody else.
I'm on OSX using Python 2.x, Selenium & Firefox
I'm automating testing a javascript webapp with Python & Selenium.
One of the links (Add File) in the application opens up a non-browser firefox window titled "File Upload" which looks like (/is?) a Finder window.
Is there a way that I could locate and control this window from my python script? I know Selenium can't do it, but I wondering if it might be possible with something like 'import applescript' and if so how?
I found atomac which allows me to control mac apps through their accessibility controls (which needed to be enabled on Mavericks for Aptana in System Preferences -> Security & Privacy -> Privacy -> Accessibility). Cool tool, but the documentation is pretty sparse. The examples provided on the page above got me to the point where I could close the window via the cancel button, but I had to review the function definitions in atomac's AXClasses.py to figure out the rest. Here's the solution.
import atomac, time
from atomac.AXKeyCodeConstants import *
# to allow me to make firefox frontmost while testing
time.sleep(5)
# get a reference to the running app
firefox = atomac.getAppRefByLocalizedName('Firefox')
# get the window of the reference
firefoxwindow = firefox.windowsR()[0]
# send key sequence to go to my home folder
firefoxwindow.sendKeyWithModifiers('h',[COMMAND,SHIFT])
# send key sequence to select first file there
firefoxwindow.sendKeyWithModifiers('a',[COMMAND])
# press the now active Open button
openbutton = firefoxwindow.buttons('Open')[0]
openbutton.Press()
It's theoretically possible, but really awkward. I'll give you a bunch of links--not ideal, I know, but you could write a book on this.
You'd need to start by enabling AppleScript control of the GUI. Then you'll want to read up on how to control the GUI from within Applescript. However, you wanted to use Python and not AppleScript, so then you'll need to install PyObjC, which is a Python to Cocoa bridge. You'd need to use the Scripting Bridge framework and figure out (from the extremely thin documentation) how to translate the AppleScript docs to Python.
I am using PAMIE to auto log in to websites and I have a couple to do. I got the scripts down to do this but I can't get PAMIE to open a new IE window so when I run the script it just opens one logs in and then when the next one is open it closes the first and opens the second and so on. So how do I get PAMIE to open new windows. This is what I have..
website="https://website"
ie.navigate(website)
ie.setTextBox("username","Myusername")
ie.setTextBox("password","mypassword")
ie.clickButton("btnSubmit")
Then I want to do this again but need it in new window.
website="https://website"
ie.navigate(website)
ie.setTextBox("username","Myusername")
ie.setTextBox("password","mypassword")
ie.clickButton("btnSubmit")
I tried ie.new before navigate(website), if someone could please tell me what command to open a new window I would appreciate it. I have also trie ie.change.window, and can't get it to work. Thanks
The web page is being re-opened in a single IE instance, because you're only using one PAMIE instance. If you really want multiple IE windows open, you can use multiple PAMIE instances.
Here is one very simple and crude example. Note that your import line may be slightly different than mine.
from pamie30 import PAM30
ie1 = PAM30.PAMIE("http://www.google.com")
ie2 = PAM30.PAMIE("http://news.google.com")
So now you can use ie1.navigate(), or ie2.navigate(), etc. to fill out the forms on your websites.
For example, to use the first IE instance:
ie1.setTextBox("q","my text goes here")
ie1.clickButton("btnK")
And when you're done with an instance you can kill it (it will leave the web page open, if you haven't done anything else with it), this just kills the Python object:
ie1 = None