03-10-2015 09:24 AM
There is an option in the Finder in Mac OS X to open files with the specified application. I tried it with my LV app, but unfortunately I haven't found any way to read out the filename passed to the app.
(The Application/Command Line Arguments Property didn't work in this case.)
Has anyone ever tried to pass files to a LV app in Mac OS X? I mean not in the command line but in the Finder.
Thanks in advance
03-10-2015 11:47 AM
Have you tried Get Info to set Open with: to your application? While I have not tired it, that is the way the Finder associates a file with an application.
Lynn
03-10-2015 11:58 AM
Hi, I tried it 2 ways:
1 - clicking on the file with the right button -> Open With... -> ...
2 - the way you just mentioned: Get Info/Open With/...
None of them worked 😞 .
PT
03-10-2015 12:19 PM
How does your app open files when you run it and try to open a file? I am thinking that it may have something to do with how your app handles files.
I think the Finder does something similar to an Apple Script like Tell App <app name> Open <file name>. If your app cannot handle that, it may not respond to the Finder.
Lynn
03-11-2015 04:57 AM
It's a simple app to present log files (with filtering, searching, and further tools). The original plan was to open the files from the GUI with a Path control (it's like that now), and the idea to make it possible to open the files from the Finder came later.
Anyway, it could even be an empty App, the main question is if it is even possible to get the filename in a LV App if we open it in Finder.
(I don't remember if I ever tried something like that in Windows. Maybe it's not possible at all. However I would be surprised, I'm sure NI has already been asked about it.)
03-12-2015 09:57 AM
Hi,
When I understand this right - and as I am not so much of a MAC Expert - you want to do the following:
1. You are in a file finder, where you can click on files an select: "open with ProgrammXY"
2. That ProgrammXY should be a LabVIEW App you created that can open files for Analysis.
3. The LabVIEW App catches from somewhere the path-string and name of the file that was selected to be opened with your LabVIEWApp, like from some
kind of property node or function.
4. How to do that?
I do not think that is possible, at least I do not know a way to do that in Windows so I doubt there is a way to do that in MAC OS.
<<Anyway, it could even be an empty App, the main question is if it is even possible to get the filename in a LV App if we open it in Finder.
When you cannot configure the Finder in a way so that he writes the file name as a command line parameter in the opening call .- exuse me if that is not MAC vocabulary - I do not see a way how to do this.
Regards
René
09-20-2019 01:24 AM - edited 09-20-2019 01:25 AM
Hi Shaper1981,
Don't know if you're still interested in this topic, but I can provide a detailed workaround regarding how to open files (either by double-click or choose "Open With...") with LV built app on macOS.
A little background:
When opening files, windows platform passes file paths to executables as arguments, using "Command Line Arguments Property" in LV executables can receive file paths and perform actions on those files. However, macOS handles "open file" in a way differs from windows (See this link for more info), in short, file paths are not passed as arguments to LV app, if you force to open files by ⌥+⌘+Draging files onto LV app, error message "App is damaged" would pop up.
Goals:
1. Create an app that can handle files, pass file paths as arguments to LV app via following shell script. You can build by Xcode if you're an experienced developer, or you can build one using built-in app called "Automator.app".
open -a /Path/to/LV.app --args filepath1 filepath2
2. Modify info.plist of file-handler app, associate specified file types so that you can open with double-click.
Workaround:
1. Place "Open Application Reference" and "Property Node: Command Line Arguments" in block diagram of your main VI in LabVIEW, then start building application (Be sure to check "pass all arguments"). For demo, I add an Array Indicator to display received arguments.
2. Open Automator.app and select “Application”, now you should see Action Library on the left and blank workflow section on the right.
Search action “run applescript” and drag to workflow section, paste following AppleScript code (overwrite given template).
on esc_char(x, char) --Adding backslash before char set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to char set x_list to text items of x set AppleScript's text item delimiters to "\\" & char set x to x_list as text set AppleScript's text item delimiters to oldDelimiters return x end esc_char on esc(x) --Adding backslash before special string repeat with char in {" ", "(", ")", "{", "}", "[", "]", "!", "#", "$", "%", "&", "|", "*", "=", ";", "'", "\"", "?", "<", ">", ","} if char is in x then set x to esc_char(x, char) end if end repeat return x end esc on run {input, parameters} set args to "" --This is the arguments pass to LV.app set thisAppPath to POSIX path of (path to me as text) --This is the path to THIS app set TargetApp to esc(thisAppPath & "Contents/Core.app") --Rename LV built app to Core.app, and place it under ThisApp/Contents/ if (length of input = 0) then --No input, directly open LV app do shell script "open -a " & TargetApp else repeat with i in input --else, get input files' path and pass to LV app via shell script set filePath to esc(POSIX path of i) set args to args & filePath & " " end repeat do shell script "open -a " & TargetApp & " --args " & args end if end run
Explanations: First two functions are used for escaping special characters in path string, in order to be recognized by Terminal. The rest function does what I said in Goals.
3. Save this app to any place you like, let's call it "OpenFile.app", control-click this app to "Show Package Contents", navigate to Contents folder where you can see info.plist, Resources folder. If the AppleScript code is NOT modified, you should rename LV-built app to Core.app and move it under OpenFile.app/Contents/, including any LV support folders if you have any to make sure LV-built app can run without error.
4. Now you can Drag files onto OpenFile.app, LV built app can receive file paths as arguments without error.
At this point, you can change the default app of ANY file type in "Get Info -> Open with", which means you can double click the specified type of file and eventually open in LV built app.
5. We can also change the display icons for specified file type and display OpenFile.app on "Open with..." list by modify info.plist of OpenFile.app.
The customized icon file (.icns) should be place under OpenFile.app/Contents/Resources/, and name should match the one in info.plist. Finally, run following code to refresh Launch Services (Change path accordingly):
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /PATH/TO/OpenFile.app
I attached demo application "OpenFile.app", it can be opened by Automator.app, feel free to play with it, but remember, info.plist and Resources folder will be initialized if you save changes in Automator, save carefully.
This is the end of the tutorial, hope it helps.
Regards,