Changing Alias Original based on whether a Volume Exists or not

Hi All,

I currently have this script written to accomplish my goal, but it only finishes successfully when the volume in question exists. For some reason, if it doesn’t exist the script errors out. If I change the localSessions variable to cloudSessions, just like the statement when the volume doesn’t exist, it works, as long as the volume still exists…very strange. Anyone know why this is happening? Script is below. I’m sorry I couldn’t explain further, but it will make a lot more sense when you look at the code :slight_smile:



set theAlias to (path to desktop as text) & "Protools Sessions"
set localSessions to "Samsung_T3:Protools Sessions"
set cloudSessions to "Google Drive:My Drive:Protools Sessions"
tell application "Finder"
	if exists "Samsung_T3" then set original item of file theAlias to localSessions
	if not (exists "Samsung_T3") then set original item of file theAlias to cloudSessions
end tell


You’re asking if a string exists, not a file or folder – you can’t just use paths or names.

Try something like this:

set theAlias to (path to desktop as text) & "Protools Sessions"
set localSessions to "Samsung_T3:Protools Sessions"
set cloudSessions to "Google Drive:My Drive:Protools Sessions"
try
	set theOriginal to localSessions as alias
on error
	set theOriginal to cloudSessions as alias
end try
tell application "Finder"
	set original item of file theAlias to theOriginal
end tell

Hi Shane,

Thank you so much, that looks very logical, but unfortunately still produces the same error I had before. For some reason, it seems to be dependant on whether or not the Samsung volume exists. If I switch the localsessions and cloudsessions variables around, while the volume is present, it changes the alias original for either of them without issue. But as soon as the Samsung harddrive disappears, it throws an error that it can’t set the alias to the samsung_t3:Protools Sessions as alias. So strange…I even tried surrounding the set statements with try blocks with no luck…thoughts?

So what happens if you run the script as posted and the Samsung drive isn’t mounted?

both your script and my original script give me this message if the samsung drive is not mounted. If it is mounted, I can set the original to either cloudSessions or localSessions without a problem and it changes the alias files correctly, with both scripts.

error “Finder got an error: Can’t set original item of alias file "Protools Sessions" of folder "Desktop" of folder "roccofiorentino" of folder "Users" of startup disk to "Google Drive:My Drive:Protools Sessions".” number -10006 from original item of alias file “Protools Sessions” of folder “Desktop” of folder “roccofiorentino” of folder “Users” of startup disk

Also, as a sidenote, how do I subscribe to a topic so that macscripter notifies me by email? There used to be a checkbox to do this but now I’m not seeing it…

I don’t think so. That message is showing "Google Drive:My Drive:Protools Sessions" as a string, which is what your original code tried to use. If you run my code, which uses an alias, you can’t get an error message like that.

Please run the script as posted and report what happens.

When looking at your script I would agree with you. But I guess the computer doesn’t think like us, because your script gives me the same error, with a little more text before it. Both this error and the one before were copied directly from the script log. The dialog that appears when running either script does not show the \ in the folder path, not sure why. The error from your script is:

tell application “Finder”
set original item of file “Macintosh HD:Users:roccofiorentino:Desktop:Protools Sessions” to alias “Google Drive:My Drive:Protools Sessions:”
→ error number -1728 from original item of alias file “Protools Sessions” of folder “Desktop” of folder “roccofiorentino” of folder “Users” of startup disk
Result:
error “Finder got an error: Can’t set original item of alias file "Protools Sessions" of folder "Desktop" of folder "roccofiorentino" of folder "Users" of startup disk to alias "Google Drive:My Drive:Protools Sessions:".” number -10006 from original item of alias file “Protools Sessions” of folder “Desktop” of folder “roccofiorentino” of folder “Users” of startup disk

I’m wondering if the error has something to do with path conversions? I’ve tried different paths and conversions with no luck yet.

The important difference is that that version confirms that the alias was successfully created. Not that it’s going to help you, unfortunately. Error -10006 is errAEWriteDenied, and I’m guessing the script is failing because the Finder doesn’t like something about the Google drive.

Can you make the change manually in the Finder at all?

Hi Shane,

Yes, I can make the change manually if I select a new original. But I need the alias to change based on whether or not the drive exists, so that it doesn’t prompt me to “fix” the alias when the drive doesn’t exist. It may not like the google drive volume because it’s a virtual network drive (google’s application Google File Stream is creating it), but that doesn’t seem to matter because I just re-confirmed that if the samsung drive is connected, it will set the original to google or samsung, depending on the variable I replace. But as soon as I eject that volume, it won’t change the original path, even if it’s a path unrelated to the task. For example, I changed both local and cloud session variables to the desktop folder separately and it wouldn’t map the alias there either, until I connected the samsung again. Very strange…

perhaps you could try a different approach. Make alias files for both drives, and then swap and/or rename the files depending on which volume is mounted.

Yes, I could do that for now, I guess, but I feel like there’s something really simple that’s stopping the current script from working, and I would like to still try and figure that out. :slight_smile: I’m one of those people where when something doesn’t work correctly I stand play with it until does. haha Anyway, I’ll try that for now and see what happens. My only fear with that is that if I’m trying to access that alias at the exact time when it’s replacing/renaming, etc. I’m not sure what the finder would do/how it would deal wit that. If you think of anything in the meantime please let me know.

Thanks so much,

Rocco

Ok…so I’ve now converted this script to using the file manager library, because it’s awesome :slight_smile: I’m also now replacing the alias file with another one specifically for each task. However, it’s still having a problem replacing it seems. If no alias is in the destination, the script executes perfectly. But as soon as that file already exists, it seems like it replaces it, but the alias original never changes. See script below:



use scripting additions
use theLib : script "FileManagerLib" version "2.1"

set theAlias to (path to desktop) as text
set cloudSessions to (path to home folder) & "Pro Tools Sessions Shortcuts:" & "Cloud:" & "Protools Sessions" as text
set localSessions to (path to home folder) & "Pro Tools Sessions Shortcuts:" & "Local:" & "Protools Sessions" as text
property samsung : "Samsung_T3"

tell application "Finder"
	if exists samsung then
		copy object localSessions to folder theAlias with replacing
		
	else
		copy object cloudSessions to folder theAlias with replacing
		
	end if
end tell


Leave the Finder out of it:

if exists object samsung then
	copy object localSessions to folder theAlias with replacing
else
	copy object cloudSessions to folder theAlias with replacing
end if

Ok, cool. Didn’t know I didn’t need finder to be able to check if the volume existed or not. But still, same thing happens. If the file is already present, it won’t change the original it points to. Is there a way to make the file manager output what it’s doing to the script log? Maybe it’s not copying for some reason when the file is there, even though I’m specifically telling it to replace? I’m stumped…

If the copying fails, an error should be thrown.

nope, no error…just doesn’t change the original location unless the file doesn’t exist in the destination folder. Anything you can think of?..

You could try deleting the destination file first. Then you can see if the copy worked easily enough.

I did, that’s what I’m saying. When I delete the destination file before running the script, it works every time, and copies the correct alias file. But if the file is already there, the original of the new alias doesn’t change. It’s almost as if because it’s an alias that makes it different somehow from a normal file, and thus something gets weird when replacing attributes…I don’t know, that’s the only thing I can think of. Or are you saying delete the file every time inside the script?

Exactly.