For a minute there I thought you were asking the same question again as last time.
But realise now you want to know how to use Inspect Element to construct your own code.
In the example you give: document.forms[WHATGOESHERE?].click()
The WHATGOESHERE would be the form name.
i.e document.forms['theFormName'].click()
Your website in their wisdom has named the form 'form'
<form method="post" action="/cgi-bin/RNAfold.cgi" enctype="multipart/form-data" name="form">
<input type="hidden" name="PAGE" value="2">
i.e document.forms['form'].click()
But this would not click the input button
You can use the submit() function dot syntax'd on the end :
document.forms['form'].submit()
Safari Applescript : do JavaScript "document.forms['form'].submit()"
Also
In the code I provided you in your last question. I used:
tell document 1
do JavaScript "document.getElementsByClassName('proceed')[0].click()"
end tell
This uses the class Name proceed of the forms input element seen here: class="proceed"
<input value="" name="proceed" type="submit" class="proceed" onmouseover="this.style.cursor="pointer"" style="cursor: pointer;">
The getElementsByClassName('proceed')[0]
does exactly what it says.
It gets the Elements By ClassName 'proceed'.
The [0] means it will give you the first element in it's results from the Array that would be returned. The array is counted from 0-9. So the first item would be item 0.
A good place to get working examples and information about Javascript is at www.w3schools.com On the front page the have links to their HTML and Javascript examples and Tutorials. The elements of the HTML Dom and Javascript functions are listed for easy access.
It appears the following line is returning an empty list:
every file of folder (choose folder) whose name extension is filetype
As an experiment, try a different suffix matching approach:
every file of folder (choose folder) whose name ends with ".wad"
In the Finder, make sure the .wad
files are in fact showing their complete name. Do this with Get Info on one wad
file in the Finder. It is unlikely but possible that the true file suffix is being hidden and thus not being matched.
Best Answer
The code snippet you borrowed doesn't relate to what you're trying to achieve, so you can safely throw that away.
Try to avoid looking for solutions that involve simulating clicks or keypresses, as these sorts of scripts are really case-specific, liable to break easily and frequently, and prohibit any additional interaction between the user and the computer whilst it is running.
A
.dmg
file (or disk image) is an item on the filesystem, which means it can be manipulated using AppleScript. You don't even have to have the.dmg
window open. It sounds like you already know the name of the file you wish to be opened.Let's say that when you double-click your
.dmg
file to mount (open) it, the name of the disk that appears on your desktop (or in the sidebar of a Finder window) is"my dmg"
(this may be different from the name of the.dmg
file itself, but it may be the same). Let's then say that there's a file called"some file.txt"
contained within the disk image that you wish to open. The path to this file will be located at:/Volumes/my dmg/some file.txt
Therefore, your entire AppleScript that will open the file (as if the user had double-clicked on it) will be:
or alternatively:
Both of these scripts are essentially identical.
However...
A limitation of both the method I've outlined above, and of your original notion involving simulated clicks, is that you won't be able to dictate that the file being opened should appear on a different desktop/screen that isn't the one that is currently active.
Clicking on the file necessarily means that the active desktop/screen switches to the one on which the window containing the file is open. You can perform a similar switch to in AppleScript, so that the desktop/screen on which the
.dmg
file is open becomes the active one:This would be incorporated into the previous code to produce a combined script that looks like this: