Wednesday, May 23, 2018

#1 2018-05-15 03:59:25 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

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 smile

Applescript:



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

Offline

 

#2 2018-05-15 11:14:22 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5327

Re: Changing Alias Original based on whether a Volume Exists or not

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

Try something like this:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Online

 

#3 2018-05-16 09:28:10 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: Changing Alias Original based on whether a Volume Exists or not

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?

Offline

 

#4 2018-05-16 10:31:21 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5327

Re: Changing Alias Original based on whether a Volume Exists or not

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Online

 

#5 2018-05-17 04:06:19 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: Changing Alias Original based on whether a Volume Exists or not

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...

Offline

 

#6 2018-05-17 05:42:24 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5327

Re: Changing Alias Original based on whether a Volume Exists or not

rfscripter wrote:

both your script and my original script give me this message



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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Online

 

#7 2018-05-17 07:34:02 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: Changing Alias Original based on whether a Volume Exists or not

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

Offline

 

#8 2018-05-17 08:31:39 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: Changing Alias Original based on whether a Volume Exists or not

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

Offline

 

#9 2018-05-17 08:36:12 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5327

Re: Changing Alias Original based on whether a Volume Exists or not

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?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Online

 

#10 2018-05-17 08:57:10 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: Changing Alias Original based on whether a Volume Exists or not

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...

Offline

 

#11 2018-05-17 09:30:16 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5327

Re: Changing Alias Original based on whether a Volume Exists or not

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Online

 

#12 Yesterday 02:42:36 pm

rfscripter
Member
From:: New Jersey, United States
Registered: 2014-04-20
Posts: 71
Website

Re: Changing Alias Original based on whether a Volume Exists or not

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. 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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)