Dialog jumps out of Series (I know it's my fault!)

I really wish I could give back to this Forum, there is so much knowledge here, and I feel like a grain of sand learning about the ocean.

Anyways… the Script should…

¢ Unhide the User Library
¢ Get the Users name
¢ Find if a certain file exists and notify the user by Dialog
¢ Flags if the file does NOT exist
¢ Ask if the user would like to Delete the file
¢ Cancel if the user does NOT want to Delete the file

In the Script below, all of the above works, except the Dialog I would like to place on the initial ‘Cancel’ button, isn’t in the correct place. I wish to use it on the first dialog. So when the script checks if the file exists, it would then display the alternate dialog.

do shell script "chflags nohidden ~/Library/"

tell application "System Events"
	set CC_User to name of current user
end tell

tell application "Finder"
	set Del_Path to "/Users/" & CC_User & "/Library/Caches/Adobe InDesign/Version 11.0/en_GB/InDesign Recovery/RecoveryData" as POSIX file
	try
		if exists file Del_Path then
			display dialog "Temporary recovery files have been found. To clear InDesign's short term memory, click continue" buttons {"Cancel", "Continue"} default button 2 cancel button 1 with title "Adobe InDesign" giving up after 10
			if button returned of result = "Continue" then
				delete Del_Path
			else
				if button returned of result = "Cancel" then
					display dialog "No temporary Adobe InDesign files were found" buttons {"Continue without action"} default button 1 with icon caution giving up after 10
				end if
			end if
		end if
	end try
end tell
			on error display dialog "No temporary Adobe InDesign files were found" buttons {"Continue without action"} default button 1 with icon caution giving up after 10

The file flags if it exists. The user can action and delete, and I can also cancel if we don’t want to delete. But I can’t make the dialog go onto the initial Cancel.

Does that even make sense!

Hi,

First of all, the user library doesn’t need to be unhidden to perform Finder actions.

Second of all, the path to the temporary file can be specified regardless of the name of the current user


set userLibrary to path to library folder from user domain as text
set Del_Path to userLibrary & "Caches:Adobe InDesign:Version 11.0:en_GB:InDesign Recovery:RecoveryData"

But consider that in the path the Indesign version (11.0) and the locale (en_GB) can be different.

To get the file regardless of version and locale you could use


tell application "Finder"
	set IndesignFolder to folder (userLibrary & "Caches:Adobe InDesign:")
	set versionFolder to 1st folder of IndesignFolder whose name begins with "Version"
	set localeFolder to 1st folder of versionFolder
	set Del_Path to file "RecoveryData" of folder "InDesign Recovery" of localeFolder
...

The script can be simplified, I’m not sure that the dialogs are as your requested, but try this


-- do shell script "chflags nohidden ~/Library/"

set userLibrary to path to library folder from user domain as text
set Del_Path to userLibrary & "Caches:Adobe InDesign:Version 11.0:en_GB:InDesign Recovery:RecoveryData"

tell application "Finder"
	if exists file Del_Path then
		display dialog "Temporary recovery files have been found. To clear InDesign's short term memory, click continue" buttons {"Cancel", "Continue"} default button 2 with title "Adobe InDesign" giving up after 10
		delete file Del_Path
	else
		display dialog "No temporary Adobe InDesign files were found" buttons {"Continue without action"} default button 1 with icon caution giving up after 10
	end if
end tell


In any display dialog statements the script will be aborted by throwing error -128 if the user presses Cancel

If you want to handle the giving up in the first dialog replace the delete line with

if gave up of result is false then delete file Del_Path

In this case the file will only be deleted if the user presses Continue, but not in case of giving up

Edit: Stefan posted just a few minutes prior to me with almost the identical method that I advised, so I have removed my code. There is a double reference to the file specifier in your”the OP”code and “Try” blocks prevent errors from being reported, so they should be placed with care. If you want to give back to the forum, there’s always the “Donations” link.

Ah, yours is so much more elegant than my hacksaw approach. Thank you for the tips, and the outcome is exactly what I was aiming for :cool:

How would one go about accounting for the variable numbered version (11.0)? Could we use a Regular Expression such as :

“Caches:Adobe InDesign:Version [\d]:en_GB:InDesign Recovery:RecoveryData” … or am I mixing languages!

I updated the post with a suggestion to get the temporary file independent of version and locale.

But consider that using the relative method Del_Path is a Finder specifier object and you have to omit the file keyword later when using it.

Back to your dialog.

When you create it you states : cancel button 1

Doing that the script never receive info about the Cancel button because what you asked is to use the Cancel button to force a silent exit exactly like error number -128.

Here, after removing the instruction cancel button 1, the script receive the button but it’s due to the fact that I use the system in French.
If I replace the string “Cancel” by “Annuler” the script doesn’t see the button because Annuler is the french translation of Cancel.

Happily, since many years we may fool the system.
If I replace the string “Annuler” by " Annuler ", yes one space before and one space behind, the script will receive the button.

On your side you may replace “Cancel” by " Cancel " to get the same result.
Of course pressing escape will no longer be treated as a shortcut for the click upon Cancel.

As I’m lazy I would define the string only once :

set path2app to path to application id "com.apple.itunes.connect.ApplicationLoader"
set Continue_loc to localized string "Continue" from table "Localizable" in bundle (path2app as «class furl»)
set Cancel_loc to localized string "Cancel" from table "Localizable" in bundle (path2app as «class furl»)
set customCancel_loc to space & Cancel_loc & space

display dialog "Temporary recovery files have been found. To clear InDesign's short term memory, click continue" buttons {customCancel,Continue_loc"} default button 2 with title "Adobe InDesign" giving up after 10
if button returned of result = Continue_loc then
	delete Del_Path
else
	if button returned of result = customCancel_loc then
		display dialog "No temporary Adobe InDesign files were found" buttons {"Continue without action"} default button 1 with icon caution giving up after 10
	end if
end if

Yvan KOENIG running El Capitan 10.11.3 in French (VALLAURIS, France) lundi 29 février 2016 20:53:52

I’ve taken onboard the comments above (that I could resolve against my knowledge and understanding), and have formed the below…

Which should in theory account for the the file being in a slightly different location etc. BUT, I STILL can’t make the “No temporary file” dialog display in the instance where Del_Path returns no file (RecoveryData). I just get a script error. What am I failing at?!

tell application "Finder"
	set userLibrary to path to library folder from user domain as text
	set IndesignFolder to folder (userLibrary & "Caches:Adobe InDesign:")
	set versionFolder to 1st folder of IndesignFolder whose name begins with "Version"
	set localeFolder to 1st folder of versionFolder
	set Del_Path to file "RecoveryData" of folder "InDesign Recovery" of localeFolder
	if exists Del_Path then
		display dialog "Temporary recovery files have been found. To clear InDesign's short term memory, click continue" buttons {"Cancel", "Continue"} default button 2 with title "Adobe InDesign" giving up after 10
		delete Del_Path
	else
		display dialog "No temporary Adobe InDesign files were found" buttons {"Continue without action"} default button 1 with icon caution giving up after 10
	end if
end tell

I’ve looked over your comments, thanks.

Your solution is a bit beyond me! I’m sure it seems straightforward to you, but I can’t work my way through it. Thanks though. I will return when I’ve increased my knowledge.

The issue is that the Finder throws an error if a file specifier (file x of folder y …) is not valid.

Now we’re using this error


set userLibrary to path to library folder from user domain as text
tell application "Finder"
	activate
	set IndesignFolder to folder (userLibrary & "Caches:Adobe InDesign:")
	set versionFolder to 1st folder of IndesignFolder whose name begins with "Version"
	set localeFolder to 1st folder of versionFolder
	try
		set Del_Path to file "RecoveryData" of folder "InDesign Recovery" of localeFolder
		display dialog "Temporary recovery files have been found. To clear InDesign's short term memory, click continue" buttons {"Cancel", "Continue"} default button 2 with title "Adobe InDesign" giving up after 10
		delete Del_Path
	on error number n
		if n = -128 then return
		display dialog "No temporary Adobe InDesign files were found" buttons {"Continue without action"} default button 1 with icon caution giving up after 10
	end try
end tell


Ah, I was this close }==;)=={ to that answer!

I didn’t consider using the error code as an ‘activator’ for a further dialog.

Many thanks for your patience.

Onwards!