I am trying to launch an app, and open a specific document with it.
For example, to launch Sublime Text, I can do it using the following call
[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:#"com.sublimetext.3" options:(0) additionalEventParamDescriptor:nil
launchIdentifier:nil];
How do I pass a url of a document to the app, to make Sublime Text open this document after launch? I believe this can be done using additionalEventParamDescriptor, but I can't find an example anywhere on how to build a correct NSAppleEventDescriptor for an "open document" event.
Thanks!
Related
Good morning. I have a web page control with selenium. However, when I click the button of the site, a pop-up screen appears and I want to test that the file attachment is saved by pressing the file attachment button in it. Can you control selenium with two windows (parent, child-popup) going up and down?
I guess you want to interact with file upload dialog which is native window via selenium. That is not possible. However you can select file to upload using sendKeys without the dialog being opened.
Something like that
fileInput.sendKeys("/path/to/local/file");
I have a webpage where I click on a button and an open dialog it's opened and I should select the file to upload. After that, a pop up is displayed saying OK or KO.
I'm able to upload files when the there are files types. But in this case, the element where I click it's:
<
button type="button" read-file="_.partial(submitLang, selectedLang)" id="import-lang" class="btn btn-default"><
/button>
For the rest of the application, I use this and it works:
WebElement element = getPage().findElementById(id);
element.sendKeys(absoluteFile);
But for button types and button tag it doesn't work.
How can I do it? The tests are running on a Linux machine
Thanks a lot!
More info!!
Hi all,
The whole process is: (see image at http://imageshack.com/a/img540/6237/JoTQng.png)
Click on Import button
A dialog is opened and I select a .json file and click Open
An alert is displayed saying "Text properties have been updated".
We are using angular for the frontend and all are REST calls.
We don't have any "file=type". All three are buttons. You can found more code at
http://imageshack.com/a/img633/7299/BQhP7o.png
For a file upload with selenium, you need to find an input tag with the type "file".
Have a look at your HTML and search for it.
When you found it, the rest is pretty straightforward:
Let's say this input-element has id="import"
driver.findElement(By.id("import")).sendKeys(absoluteFile);
If you run into problems, please post more of your HTML, then I can have a look at it.
In my case, clicking on the button made an element appear in the HTML code, I assume due to javascript.
I clicked on the element (which both opens a file upload window and adds the to the HTML), and immediately after send the keys to the input element.
This creates the problem of having to close the newly opened file upload window, however this is not a problem when using --headless mode on google chrome.
I do not have a solution to close this window if you are not in headless mode for your chosen browser.
I'm creating a Media Player app using Objective-C and Cocoa and I'd like the user to be able to chose a video file on Finder, right-click, select Open With and my app. I'd implemented the Open button under the File button but have no idea about how to implement the Open With thing. How can I do that?
The Info.plist CFBundleDocumentTypes entry is how the system knows what kinds of documents your app can open.
https://developer.apple.com/library/mac/documentation/general/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685
There this AppleScript
tell application "Google Chrome" to set index of window 1 to 1
do shell script "open /Volumes"
Which opens a directory in Finder without bringing every onther Finder windows to the front.
Currently I'm using :
[[NSWorkspace sharedWorkspace] openURL:fileURL];
But it has the flaw to bring every Finder windows on the top of others.
Any idea how I could achieve the same behaviour as the AppleScript ?
You can always use NSAppleScript to run applescript code in Objective-C if Cocoa doesn't provide the functionality you want.
At a guess, -[NSWorkspace openURL:] also sends the application an activate event whereas the open process does not.
I'd recommend looking into the LaunchServices API. It's what both NSWorkspace and open use behind the scenes, but gives you more control than NSWorkspace's limited API.
--
p.s. If you do have to call out to open (or any other command line tool) from ObjC, you should use Cocoa's NSTask. (AppleScript's do shell script command is just its [crappy] equivalent of NSTask.)
I'm having trouble trying to open a file.
I download a document file somewhere, and I have a viewer to view the file on my iPhone. I want my app to open the file to the viewer.
Here's what I'm trying to do in -(IBAction)buttonPressed:
dc = [UIDocumentInteractionController interactionControllerWithURL:url];
if([dc presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES])
{
NSLog(#"menu is presented");
}
When I run the program and click trigger buttonPressed, the NSLog message is printed, and an action sheet appears with two options. One is evernote, the other one is viewer.
However, when I click either option in the action sheet popup, nothing happens.
What am I missing? Do I need to implement a delegate method?
Please help. Thanks!
i've got the answer.
i must retain dc..
fool mistake :(