Opening a .pdf file or specific folder
-
Is it possible to open a folder that is located in the "Program Files" on Windows & the "Applications" on the Mac?
-
@Steve-Mohican You should be able to use an absolute path.
Absolute paths can be dangerous but unless I'm wrong I don't think it is bad here... -
@ustk I am trying
.fromAbsolutePath
but no luck.const var Button1 = Content.getComponent("Button1"); inline function onButton1Control(component, value) { if (value) { if (Engine.getOS() == "OSX") FileSystem.fromAbsolutePath("/Applications"); else if (Engine.getOS() == "WIN") FileSystem.fromAbsolutePath("c:\Program Files"); } }; Content.getComponent("Button1").setControlCallback(onButton1Control);
-
-
@Steve-Mohican
inline function onButton1Control(component, value) { if (value) FileSystem.browseForDirectory(FileSystem.fromAbsolutePath("/Applications"), doSomething); }; Content.getComponent("Button1").setControlCallback(onButton1Control); function doSomething(dir) { Console.print(dir.toString(0)); }
-
@ustk Oh that's great, opens the browser, but it doesn't allow you to open a file.
What about only for browsing? Actually my goal is to open a .pdf file. -
@Steve-Mohican said in Opening a specific folder:
What about only for browsing? Actually my goal is to open a .pdf file.
-
Thank you guys, I will check it out!
-
-
-
@d-healey I prefer using the classic .pdf manuals, not interested in the Markdown stuff for now.
I watched the tutorial and looked into the FileSystem & File APIs.
I think we can't add a button like below - "Open Manual" button that opens the .pdf file directly. Or at least open the manual directory with a browser, and the user can select the manual and open it, I could live with that too.
-
-
@Steve-Mohican You might be able to open it directly with
File.startAsProcess()
but I've not tested it, and you'll have to handle the situation where the file isn't where you expect it. -
@d-healey said in Opening a .pdf file or specific folder:
@Steve-Mohican You might be able to open it directly with
File.startAsProcess()
but I've not tested it, and you'll have to handle the situation where the file isn't where you expect it.I think it can be handled with
isFile
. But first of all below one doesn't trigger the UserManual.pdf on my desktop.const var Button1 = Content.getComponent("Button1"); const FindFolder = FileSystem.getFolder(FileSystem.Desktop); const FindFile = FindFolder.getChildFile("UserManual.pdf"); inline function onButton1Control(component, value) { if (value) { local f = FindFile.toString(1); File.startAsProcess(FindFile.toString(1)); } }; Content.getComponent("Button1").setControlCallback(onButton1Control);
-
@Steve-Mohican said in Opening a .pdf file or specific folder:
File.startAsProcess(FindFile.toString(1));
Yup that won't work. You need to read the API doc.
-
Yup that won't work. You need to read the API doc.
Doc says
File.startAsProcess(String parameters)
So I need thatString parameter
right?So I tried to convert the folder path to the string with
toString
-
@Steve-Mohican File in this instance means the file object that you want to open, not the File class. Parameters is for when you're opening a CLI application and want to pass in some values, generally you'll just set this to
""
So what you'll want is something like
f.startAsProcess("");
-
@Steve-Mohican
If you want to use the absolute paths for addressing the manuals, you also need to check the operating systems. Another thing to mention is the macOS will want the user to grant the access to the dedicated folders. Below one should work:
const var Button1 = Content.getComponent("Button1"); inline function onButton1Control(component, value) { if (value) { if (Engine.getOS() == "OSX") { local FindFileforMac = (FileSystem.fromAbsolutePath("/Applications/MyCompany")).getChildFile("User manual.pdf"); if (FindFileforMac.isFile()) FindFileforMac.startAsProcess(""); } else if (Engine.getOS() == "WIN") { local FindFileforWin = (FileSystem.fromAbsolutePath("C:\Program Files\MyCompany")).getChildFile("User Manual.pdf"); if (FindFileforWin.isFile()) FindFileforWin.startAsProcess(""); } else Console.print("The User Manual can't be found"); } }; Content.getComponent("Button1").setControlCallback(onButton1Control);
-
@orange Wow Thanks! I've just tried and it works great.
I appreciate all of your help guys!
-
@orange it is saying function not found on "if (FindFileforMac.isFile()) FindFileforMac.startAsProcess("");"
-
@Jay This works here with the current develop branch. You need to handle the folder paths and also file name - extension in the
.getChildFile
properly.HiseSnippet 1026.3ocwV89aaTCF1WaNzt.Lwj3qHYkO.Wj1RSXC1DnJZZZBJhkz.oqae.oMm67kXUe1mr8MHBUI9Sl+CfW66RxkRZ2TDSDojn2e5G+3W+95IJYDUqkJjWvEKynHuOwe5RgYQuEDl.M7Lj288GQzFpBWn5zkYDslFi77N7GsJ7Bpgbe9qe3TBmHhnaTgPWJYQzmyRYlMZmbxOw37AjX5ErzJd+jSFFIE8jbYNfmC8aixHQWQlSGSrtcfOx6i5GyLR0TCwP0HuZmJiWNcg72DE9eISylwoVgNn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branch and it works, thanks
-
@orange The only issue I have now, in HISE it open but it doesn't open within the compile plugin. It open in HISE but not in plugin
-
@Jay Where did you locate the .pdf file? AppData folder? Send your modified snippet.