Adding network folder to finder favorites - applescript

I am trying to write an apple script that adds a certain folder from a server that has been mapped to the favorites section in finder.
What I have so far is:
tell application "finder
activate
open "path to server"
tell application :System Events"
keystroke "t" using {command down, control down}
end tell
end tell
I believe that the problem is with "path to server", I do not need the location opened just placed in the favorites section.
The result is error "finder got an error: Handler cant handle objects of this class.

Related

Expected end of line but found identifier in Script Editor

I am trying to right click a button in the application "Pro Tools."
To do this I am trying to tell script editor/apple scripts to click the button using control down (which emulates a right click on a Mac). However, I keep getting an error message when I try to compile or run the code. I receive a syntax error message that says
Expected end of line, etc. but found number.
or
Expected end of line but found identifier.
that point to using.
tell application "System Events"
tell application process "Pro Tools"
click button "Record Enable" of group "Normal Transport Buttons" of group "Transport View Cluster" of window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy" using key code 59
end tell
end tell
I have also tried using this code:
tell application "System Events"
(click button "record enable" of group "normal transport buttons" of group "transport view cluster" of window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy" of application process "Pro Tools")
using key code 59
end tell
First things first, you'll make your life easier if you use nested tell blocks, like so:
tell application "System Events"
tell application process "Pro Tools"
tell window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy"
tell group "Transport View Cluster"
tell group "Normal Transport Buttons"
click button "Record Enable"
end tell
end tell
end tell
end tell
end tell
Takes up more space, yes, but it's much easier to debug.
That being said, you might try using the perform command instead of click or key code. I mean, if there is a key equivalent for right-clicking the button that would be easiest, just use:
tell application "System Events"
tell application process "Pro Tools"
key code 59 using control down *-- or whatever*
end tell
end tell
but if not, try this first:
tell application "System Events"
tell application process "Pro Tools"
tell window "Edit: BB MASTER TEMPLATE 2019 v1-14 copy"
tell group "Transport View Cluster"
tell group "Normal Transport Buttons"
tell button "Record Enable"
log properties
log actions
end tell
end tell
end tell
end tell
end tell
end tell
and if the log shows an action for the button that seems on-point you can invoke it directly using:
tell group "Normal Transport Buttons"
tell button "Record Enable"
perform action 2 *-- or whatever*
end tell
end tell
It's hard to say more without more information...

With Applescript I need to use System Events to navigate a Finder Window that opens within an application

I'm currently writing some Applescript to import some material into software which doesn't have much applescript support and virtually no documentation on Applescript. The two methods are to somehow adapt this script to work:
on adding folder items to this_folder after receiving these_items
try
tell application "Isadora"
import media into document 1 from these_items
end tell
on error msg
display dialog "Error importing file into Isadora: " & msg
end try
end adding folder items to
However when I try to use "import media into document 1 from ________" I always get an error, in every incarnation of that combination.
My second approach then is using System Events to navigate through the menu bar to import everything. When I get to the import part of things where I can navigate and select the files, a finder window pops up. My question is:
How do I navigate this finder window within the application? This is like the inception of scripts. A finder window within a program.
I tried a few simple things like calling the front window of finder to navigate somewhere and what not. The current script that gets me to the import window is:
tell application "IsadoraCore"
activate
delay 2
tell application "System Events"
click menu bar item "File" of menu bar 1 of application process "IsadoraCore"
click menu item "Import Media..." of menu "File" of menu bar item "File" of menu bar 1 of application process "IsadoraCore"
end tell
end tell
Any help would be appreciated!
I would guess the "import media" window is a Finder window where you select a file to import. This window is easy to handle. To select the file you must have the posix path of the file. In that window if you keystroke "shift-command-g" then you get a text field where you can keystroke the posix path. For example, let's say I want to open a file in TextEdit. The file is on my desktop with the name test.txt. I can do this...
set filePath to (path to desktop as text) & "test.txt"
set posixPath to POSIX path of filePath
set aShortDelay to 0.5
tell application "TextEdit" to activate
delay aShortDelay
tell application "System Events"
keystroke "o" using command down -- bring up the "open dialog window"
end tell
delay aShortDelay
tell application "TextEdit" to activate
delay aShortDelay
tell application "System Events"
keystroke "g" using {shift down, command down} -- bring up the "goto folder sheet" in the open dialog window
delay aShortDelay
keystroke posixPath -- enter the posix file path
delay aShortDelay
keystroke return -- dismiss the "goto folder sheet"
delay aShortDelay
keystroke return -- dismiss the "open dialog window"
end tell
Notice I have delays after every command. That is good practice when you're using this type of scripting. You don't want the code to run faster than the computer can perform the tasks so the delay gives the computer time to keep up with the code. Notice that I use a variable for the delay. This way I can play with aShortDelay making it longer or shorter as needed to make the script run properly.
Good luck.
Aren’t you asking Isadora to import a list of folders? Perhaps it can only handle one folder at a time?
I don’t have Isadora to test, but you might try this:
on adding folder items to this_folder after receiving these_items
try
tell application "Isadora"
repeat with the_item in these_items
import media into document 1 from the_item
end repeat
end tell
on error msg
display dialog "Error importing file into Isadora: " & msg
end try
end adding folder items to

Applescript command that navigates to a specific folder when the attachments popup appears in safari?

I'm building an Applescript that will attach specific files when the attachment prompt appears in Safari.
I initially tried do shell script "open /Users/ea/Desktop/Guru/Deliverables/" but that just opens a new finder window. I need to know how to navigate to the correct folder once the prompt appears (see image below).
I'm sure it's simple, but I'm brand new to Applescript.
The GUI script solution would be:
tell application "System Events" to tell process "Safari"
tell window 1 to tell sheet 1
key code 5 using {shift down, command down} --shortcut for go to folder
tell sheet 1
set value of text field 1 to <POSIX path to targetfolder as text>
click button 1
end tell
end tell
end tell

'Click at' returns "System events got an error..." -Applescript

Newbie to applescript, sorry if its dumb. I have been trying to write a script to check if the network is healthy, if not go to a url and click Login button on the webpage (actually the page has 'username' and 'password' which my browser autofills). i used the following code;
try
set thePing to do shell script "/sbin/ping -o -c 1 www.google.com"
on error
tell application "Google Chrome" to open location "https://mwcp-ekm-04.adlkerala.com:8001"
delay 5
tell application "System Events"
tell process "chrome"
click at {585, 220}
end tell
end tell
end try
(I know a javascript would have been better that the 'Click at' but then i didnt know how to do that)
While running i get the following error "System Events got an error: Can’t make {585, 220} into type list." number -1700 from {585, 220} to list"
EDIT:
after some googling i managed to pull out the java code;
try
set thePing to do shell script "/sbin/ping -o -c 1 www.google.com"
on error
tell application "Safari" to open location "https://mwcp-ekm-04.adlkerala.com:8001"
delay 3
tell application "Safari"
do JavaScript "document.getElementById('submit').click();" in current tab of first window
end tell
end try
but now this returns a result "Missing Values"
i would appreciate any help
Thanks
I think click at stopped working in 10.9. Or at least
tell application "System Events" to tell process "Safari"
set frontmost to true
click at {20, 20}
end tell
works for me in 10.8 but results in an error like error "System Events got an error: Can’t make {20, 20} into type list." number -1700 from {20, 20} to list in 10.9.
Try to use MouseTools or cliclick (or JavaScript) instead.
I just answered a quite similar problem with s.o. trying to "click at desktop" (here) ...
System Events' sdef file says, that "click at" still works when sent to a "process" object [at] the { x, y } location at which to click, in global coordinates (meaning: in absolute screen coordinates, NOT relative to an app's window).
So: you cannot "click at" a file visible on desktop (as a "file" there actually is: image of group 1 of scroll area of process "Finder") but you still can click at any window / button.
Every "click", anywhere on your screen must have an "aim". It won't work like a mouse pointer.

AppleScript Clicking On dialog box

In PCSX, (ps1 emulator), i'm trying to automate the steps to play an iso. So, i'm doing this:
set thepath to path to me
set thesecondpath to POSIX path of thepath
set thethirdpath to "Contents/PSX/ROMS/img.bin"
set thefourthpath to "/Contents/PSX/PCSX.app"
set thefifthpath to thesecondpath & thefourthpath
set theultimatepath to thesecondpath & thethirdpath
tell application thefifthpath
activate
tell application "System Events"
keystroke "i" using {command down}
keystroke theultimatepath
delay 1.0
tell process "PCSX"
click button "Go"
end tell
key code 53
end tell
end tell
Running from the AppleScript Editor won't work. I made it to work running from the App it creates. PCSX and the img.bin are inside the Generated Package.
after pressing command+i, it opens a "Go to the folder" dialog, and i need to click Go and then Open
But doing this way, it won't find the dialog box. What am i doing wrong?
If Go and Open are the default buttons, try:
tell application "System Events"
keystroke return
delay 2
keystroke return
end tell
Although I don't have PCX installed here is an example of how to click the Go button from Finder's Go to Folder command.
tell application "System Events"
tell process "Finder"
click button "Go" of window "Go to Folder"
end tell
end tell
The reason your script won’t work from AppleScript Editor is that the “me” in “path to me” is the application that ran the AppleScript. When you are running the AppleScript in AppleScript Editor, that means AppleScript Editor itself. When you saved your AppleScript as a script application and ran it, the path to me pointed to your script application, because it was running its own AppleScript.
Also, this is incorrect:
tell process "Finder"
click button "Go" of window "Go to Folder"
end tell
The “Go” button is not on the window “Go to Folder.” It’s on a sheet which is attached to a Finder window which has the name of whatever folder is currently being viewed. So you have to describe the button as being on sheet 1 of window 1:
tell application "System Events"
tell process "Finder"
click button "Go" of sheet 1 of window 1
end tell
end tell
… but keep in mind that in another app, a similar looking button on a sheet may be on sheet 1 of group 1 of group 2 of window 3. UI Scripting is complicated.

Resources