VeraCrypt script stopped working after update to VeraCrypt 1.25.4

As said, VeraCrypt script stopped working after I updated it to latest version of VeraCrypt (VeraCrypt 1.25.4), I presently use version 12.4 Update 8.

I have the following script that worked fine under above mentioned version of VeraCrypt but stopped working when I upgrade VeraCrypt to the newer version (VeraCrypt 1.25.4). I use OS 11 by the way and presently have reversed back to VeraCrypt 1.24 as I need the encrypted/decrypt files almost on a daily basis.

I found the original script a while ago on the MacScripter forum and must admit that I do not understand all the steps it makes, even after reading all the posts there. However, it worked so I used it ever since as it makes login into a file super easy.

As said, I am not very good at scripting and there could be no way I would be able to write this type of script on my own. I hope the people who engaged with this originally can help me out here. Or has anybody out there maybe solved this already (ChangeAgent maybe?)? In that case would you be so kind and post the updated script for me?

Any ideas why it is no longer working? Is there anybody out there that uses VeraCrypt_1.25.4 and can help me to get it to work again?

Thanks.

use AppleScript version "2.4"
use scripting additions

tell application "VeraCrypt" to activate
tell application "System Events"
	tell application process "VeraCrypt"
		set frontmost to true
		--repeat until exists window "VeraCrypt"
		--delay 0.1 # Don't forget that this loop fails
		--end repeat
		repeat 10 times
			if exists window "VeraCrypt" then exit repeat
			delay 0.1
		end repeat
		delay 0.5
		if not (exists window "VeraCrypt") then error "The window VeraCrypt is not available"
		tell window "VeraCrypt"
			set {wLeft, wTop} to its position
			set {x, y} to {wLeft + 33, wTop + 46} # MOVED
			# Edit this instruction to change the slot to select
			set slotNum to 1 # MOVED. slotNum may be in the range : 1 thru 20
			-- get its position # May be useful to check the values in the property slots
			-- get position of groups # May be useful to check the values in the property slots
			-- get size of groups # May be useful to check the values in the property slots
			tell scroll bar 1
				if class of UI elements contains value indicator then --> {value indicator, button, button, button, button}
					set oldPos to item 2 of (get position of value indicator 1) --> 963
					-- get subrole of buttons --> {"AXIncrementArrow", "AXDecrementArrow", "AXIncrementPage", "AXDecrementPage"}
					repeat
						click button 4 --> the "AXDecrementPage" one
						set newPos to item 2 of (get position of value indicator 1)
						if newPos = oldPos then exit repeat
						set oldPos to newPos
					end repeat
				end if
				# slotNum = 1 -> select slot 1
				# slotNum = 2 -> select slot 2
				# slotNum = 3 -> select slot 3
				# slotNum = 4 -> select slot 4
				# slotNum = 5 -> select slot 5
				# slotNum = 6 -> select slot 6
				# slotNum = 7 -> select slot 7
				# slotNum = 8 -> select slot 8
				# slotNum = 9 -> select slot 9
				# slotNum = 10 -> select slot 10
				# slotNum = 11 -> select slot 11
				# slotNum = 12 -> select slot 13
				if slotNum > 13 then # EDITED so that it's supposed to behave well for slots 1 thru 13
					click button 3 # moves a page down to display slots 8 thru 20
					# slotNum = 14 -> supposed to select slot 14 but select slot ?
					# slotNum = 15 -> supposed to select slot 15 but select slot ?
					# slotNum = 16 -> supposed to select slot 16 but select slot ?
					# slotNum = 17 -> supposed to select slot 17 but select slot ?
					# slotNum = 18 -> supposed to select slot 18 but select slot ?
					# slotNum = 19 -> supposed to select slot 19 but select slot ?
					# slotNum = 20 -> supposed to select slot 20 but select slot ?
					# It appears that for slots higher than 13 you will have 
					# to make tests to learn what is returned for every value.
					set slotNum to slotNum - 12 # DON'T EDIT THIS INSTRUCTION !!. 
				end if
			end tell # scroll bar 1
		end tell # window "VeraCrypt"
	end tell # process Veracrypt
	
	set h to 18 # EDITED not sure that it's the correct value, may be 19 or 20
	
	tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & (y + slotNum * h)
	
	-- Choose text field to keystroke the path
	tell application process "VeraCrypt"
		tell window "VeraCrypt"
			tell combo box 1
				set value of attribute "AXFocused" to true
				-- delay 0.5 # may be useful here
				set its value to "/Volumes/Data/FileName" --Change as needed
			end tell # combo box 1
			click button "Mount"
		end tell # window "VeraCrypt"
	end tell # process VeraCrypt
end tell # Application System Events

delay 50

tell application "VeraCrypt" to quit

Good morning and happy Christmas.

just realised this morning that it might be helpful to tell where the script stops. it stops at the line

if class of UI elements contains value indicator then --> {value indicator, button, button, button, button}

The error message I get is

error "System Events got an error: Can’t get scroll bar 1 of window \"VeraCrypt\" of application process \"VeraCrypt\". Invalid index." number -1719 from scroll bar 1 of window "VeraCrypt" of application process "VeraCrypt"

Sorry about that folks.

Your script uses GUI scripting. With almost every new version of an application (any), the hierarchy of its windows changes. Therefore, you will have to define a new hierarchy for the VeraCrypt window.

Most likely, you will have to do it yourself. To visually view the window hierarchy 1) I recommend that you use the Script Debugger (a very handy free application), 2) insert the following before the tell window “VeraCrypt” line: return window “VeraCrypt”.

NOTE:
the error in your script throws following code line: tell scroll bar 1. So, search in the Results window of Script Debugger for some UI element that corresponds to this scroll bar. If it exists in your window… Maybe, in new VeraCrypt this scroll bar doesn’t appear all time.

morning KniazidisR, thanks for taking the time to answer.

I will need to give it a try when I am back at the machine.

OK back at the Machine.

Do I insert the line return window “VeraCrypt” as you suggest before the first or the second occurrence of the line tell window “VeraCrypt” (I did not know which one you meant but assumed first of it was the first one, and experimented with both).

The result is that if I do it with both the lines the script runs and reports no error. It shows the result

window "VeraCrypt" of application process "VeraCrypt"

and just opens VC and that is it no other actions are executed. No error pops up.

If I delete it after the second occurrence I get the same result.

This is what it looks like:

if not (exists window "VeraCrypt") then error "The window VeraCrypt is not available"
		return window "VeraCrypt"
		tell window "VeraCrypt"
			set {wLeft, wTop} to its position

OK, use following to see the hierarchy:


return UI elements of window "VeraCrypt"

On its own it does not work, so I inserted it in the position you suggested before. That works.

OMG, that gives a whole list of stuff to look at. What do I do with it? Here a sample of that I get https://ibb.co/hmMvhMw

OK solved it in case anybody else looks for this.

do shell script "open -a VeraCrypt --args '/Volumes/Path/ToFile/NameOfFile.xxx' /Volumes/NameOfFile"

And for that much more elegant.