MeTheMachine Posted November 13, 2020 Share Posted November 13, 2020 Is it possible to get the filepath of a document using Applescript? I didn't know where exactly to post this question. Thanks for any help. Quote Link to comment
Pat Stanford Posted November 13, 2020 Share Posted November 13, 2020 Probably. You can run Vectorscript commands from an AppleScript and there is a Vectorscript command that will return the file path of the active file. Perhaps better is you explain what you are actually trying to do so we can offer potentially better solutions. Quote Link to comment
MeTheMachine Posted November 13, 2020 Author Share Posted November 13, 2020 (edited) I'm trying to use a program on the Mac called Hook My goal is to link or "hook" all the PDF files I use for a drawing to the vectorworks file I'm working in. Currently, I can have 12 different sets, which is 12 different vectorworks files, and all of them have up to a dozen PDF files from Art Dept. So if I'm working on "Haunted Castle.vwx", when I invoke Hook, it will pull up all the PDFs I have linked to "Haunted Castle.vwx" file. With that in mind, I'm probably going about this all wrong. I wrote a python script that I use to capture the filepath and set it to my clipboard. Keep in mind, Im not a programmer but it works... import subprocess def Path(): filePath = vs.GetFPathName() filePath = filePath[1:] subprocess.run("pbcopy", universal_newlines=True, input=filePath) vs.AlrtDialog(filePath) Path() Following the instructions for creating integration scripts Once I run the python script, in vectorworks, I use this applescript to create the hook path -- Append clipboard to Hook Link set cp to POSIX path of clipboard -- Get Address set hookPath to "file://" & (the clipboard) And I use this applescript to create the name of the hook... using the name of the document tell application "Vectorworks 2021" set current_name to name of item 1 in windows end tell --- I tried to use the "Run python script" in Applescript but kept getting an error. I'm sure its something I'm doing wrong. I didn't know if it was possible to just get the filePath of the document in applescript? It would take the manual execution of the python script, out of the mix... I've hit my afternoon lull, so I hope this makes sense. Edited November 13, 2020 by MeTheMachine Quote Link to comment
michaelk Posted November 13, 2020 Share Posted November 13, 2020 In AppleScript isn't there a difference between "native" file path and "unix" file path? I think POSIX does the non unix flavor. But this is at the limits of my AppleScript experience 🙂 Quote Link to comment
MeTheMachine Posted November 13, 2020 Author Share Posted November 13, 2020 3 minutes ago, michaelk said: In AppleScript isn't there a difference between "native" file path and "unix" file path? I think POSIX does the non unix flavor. But this is at the limits of my AppleScript experience 🙂 Its entirely possible... I was looking at other AppleScripts examples and they were using POSIX path... Applescript makes my head hurt... Quote Link to comment
michaelk Posted November 13, 2020 Share Posted November 13, 2020 Me too! I played around with it a while ago because you can run a VectorScript inside an AppleScript. I don't necessarily recommend it. 🙂 Quote Link to comment
Pat Stanford Posted November 14, 2020 Share Posted November 14, 2020 The following AppleScript gets the full path of the frontmost VW file onto the clipboard. There is probably a more elegant way to do this using python, but I am not enough of a python expert to make it happen. At least I figures some way to get the contents of a variable out of VW and into a form that can be used in the rest of the AppleScript. You can't copy a Text object in VW and paste it into a different application. So I Edit the text block, Select All, and copy that. That can be pasted into a different application. In the version of VW I am running I get a Beta Undo Error if I don't use the UndoOff command at the top. Undo will (should) automatically restart when the procedure ends. And since there are no variables in the VectorScript, you could actually delete the Procedure, Begin, End, and Run lines. HTH tell application "Vectorworks 2021" run VectorScript " Procedure Test; Begin UndoOff; CreateText(GetFPathName); Redraw; EditObjectSpecial(LNewObj,0); DoMenuTextByName('Select All',0); DoMenuTextByName('Copy',0); SetTool(-240); DelObject(LNewObj); End; Run(Test);" end tell set PTS to get the clipboard 1 Quote Link to comment
MeTheMachine Posted November 14, 2020 Author Share Posted November 14, 2020 13 hours ago, Pat Stanford said: The following AppleScript gets the full path of the frontmost VW file onto the clipboard. There is probably a more elegant way to do this using python, but I am not enough of a python expert to make it happen. At least I figures some way to get the contents of a variable out of VW and into a form that can be used in the rest of the AppleScript. You can't copy a Text object in VW and paste it into a different application. So I Edit the text block, Select All, and copy that. That can be pasted into a different application. In the version of VW I am running I get a Beta Undo Error if I don't use the UndoOff command at the top. Undo will (should) automatically restart when the procedure ends. And since there are no variables in the VectorScript, you could actually delete the Procedure, Begin, End, and Run lines. HTH tell application "Vectorworks 2021" run VectorScript " Procedure Test; Begin UndoOff; CreateText(GetFPathName); Redraw; EditObjectSpecial(LNewObj,0); DoMenuTextByName('Select All',0); DoMenuTextByName('Copy',0); SetTool(-240); DelObject(LNewObj); End; Run(Test);" end tell set PTS to get the clipboard Thank you very much, Pat! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.