Jump to content

Getting the filepath via AppleScript


Recommended Posts

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 by MeTheMachine
Link to comment
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...

Link to comment

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

 

  • Like 1
Link to comment
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!

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...