Sunday, December 17, 2017

#1 2017-09-29 09:03:39 am

myers022
Member
Registered: 2016-01-12
Posts: 6

Need Help Resolving - Can't Get every file of said folder?

With the help of some users on this form I was able to create this script below which lets you choose a folder then choose which folders within the folder you want to rsync into a OneDrive Backup Folder.

Basically were migrating from a on site network storage to OneDrive for Business and want to create a script that as easy as possible for our users.

The issue I have is I dont want the users to be able to choose the original folder, I want to set the variable up front.

In the script I use:

Applescript:

set theFolder to (choose folder with prompt "Please Choose The Root of Your H Drive
Or The Folder That Looks Like:    "
& userName & "$")

If I use:

Applescript:

set theFolder to "/Volumes/MYERSMI5$/"

I get " Can't Get every file of said folder " error message

How Do I set the theFolder for this script ahead of time instead of asking the user to pick the folder?



Applescript:

set OuserName to do shell script "whoami"
set userName to do shell script "echo " & OuserName & " | tr a-z A-Z"


tell application "Finder"
   if not (disk userName exists) then
       mount volume "SMB Server/" & userName & "$"
       
   end if
   
   delay 2
   
   set theDialogText to "
       - Mac H-Drive Migration Tool -
       
This Application Will Migrate a Copy of Your H Drive Data
to your OneDrive for Buisness Folder Locally on Your Mac

Migration Backup Location:
/Users/"
& OuserName & "/OneDrive Folder/H-Drive Migration Backup

** Important **    
In the Next Window Please Choose
The Root Folder of Your H Drive
The Drive Label Should Look Like:    "
& userName & "$"
   
   display dialog theDialogText
   
   
   
   set theFolder to (choose folder with prompt "Please Choose The Root of Your H Drive
   Or The Folder That Looks Like:    "
& userName & "$")
   
   
   
   
   
   do shell script "mkdir -p ~/'OneDrive Folder'/'H-Drive Migration Backup'"
   
   set HDriveBackupFolder to ((path to home folder as text) & "OneDrive Folder:H-Drive Migration Backup")
   
   
   
   
   set AppName to "OneDrive.app"
   
   tell application "Finder" to set Answer_ to exists application file ((path to applications folder as string) & AppName)
   if Answer_ is false then
       
       beep
       beep
       beep
       beep
       beep
       
       
       
   end if
   
   delay 1.5
   
   tell application "Finder"
       activate
       set theFolderNames to name of folders of theFolder
       set theChosenNames to (choose from list theFolderNames with prompt "Choose Which Folders to Backup, Please Hold Down The ⌘ Key To Choose Multiple Folders " with multiple selections allowed)
       if (theChosenNames is false) then return
       
       set HDriveBackupFolder to ((path to home folder as text) & "OneDrive Folder:H-Drive Migration Backup")
   end tell
   
   repeat with thisName in theChosenNames
       
       
       
       tell application "Terminal"
           
           do script ("rsync -avpz --delete " & (quoted form of POSIX path of ((theFolder as text) & thisName)) & space & (quoted form of POSIX path of HDriveBackupFolder))
           
           
           
       end tell
       
   end repeat
end tell

Offline

 

#2 2017-09-30 05:16:55 am

alastor933
Member
From:: Utrecht, NL
Registered: 2008-09-12
Posts: 544

Re: Need Help Resolving - Can't Get every file of said folder?

Where the script actually uses the theFolder variable it expects an AppleScript alias, which is what choose folder returns. Now you're giving it a string in POSIX format. You need to transform that string, like so:

Applescript:

set theFolder to alias (POSIX file "/Volumes/MYERSMI5$/")

Note this will fail when that volume isn't mounted!

On a side note: you have nested tell blocks, which is never a good idea.
Remove the 2nd tell Finder/end tell (not the code it contains), and move the activate command to the top, after the 1st tell Finder.
Move the tell Terminal code to the end of the script (including the repeat loop - it might be neater to have the repeat inside the tell Terminal block, not the other way around).

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)