Get SVN URL of a file and copy to clipboard

Hello folks.

First, let me tell you that I am not a programmer. I can code HTML and CSS, and a bit of PHP e jQuery. I’ve seen some Applescript possibilites, and then I’ve started trying to produce something to speed up my workflow. Now I am looking for some help to optimize my code.

The code which I’ve made grabs a file path (via drag and drop) and puts it into a Terminal command, then outputs its SVN URL to the clipboard, with a dialog telling the URL as copied.

The problem is when the Terminal is activated, it keeps opening many processes before the login is made, and then the code proceeds. Also, the notification dialog appears BEFORE the terminal action is done, so when I click “close” on the dialog window, the scripts finishes and the URL isn’t copied.

The logic is:

  • Grab file path via drag and drop
  • Puts the file path into a Terminal command “svn info filepath | grep URL | pbcopy”
    (here’s the problem ” Terminal needs some time before logging in and then executing the code)
  • SVN URL is copied to the clipboard
  • A dialog telling the URL is ready to be paste is shown.

Here’s the code:

on open {macFolder}
	
	-- Grab path file
	set my text item delimiters to ":"
	set strFilePath to text items 2 through -1 of (macFolder as string)
	set my text item delimiters to "/"

	
	-- Grab the SVN Path
	tell application "Terminal"
		do script "svn info " & "/" & strFilePath & " | grep URL | pbcopy"
	end tell
	set my text item delimiters to "URL: "
	set my text item delimiters to ""
	
	-- kill Terminal
	set app_name to "Terminal"
	set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
	if the_pid is not "" then do shell script ("kill -9 " & the_pid)

	-- Display the dialog
	display dialog "SVN URL copied. ⌘+V to paste." buttons {"Close"} default button 1
	
end open

I hope someone can help me optimizing this code. I think a line of code to make Terminal “wait” for its action to be done before proceeding should do the work.

I also hope I’ve made my question clear. I not used to write in english.

Thanks in advance.

Hello.

Extract the path of whatever has been dropped onto your droplet.

Make that path into a posix path.

Cd to it in terminal.

at the end of your pipe, add a "; touch trigger.file (Trigger file won’t be made before the pipe is done.)

Outside the tell block, test if the trigger file exists in a loop, if it isn’t, then delay for 1 sec, and look again.
When the file exists, delete it, and move in your script.

Good luck!