Applescript to duplicate file from mounted volume to desktop - applescript

I am just getting starteded with Applescript and need some help with a simple file copy from a Windows server. I am mounting a volume to a Windows share and I need to copy the files from that folder to the desktop. Here's the AppleScript I have so far.
tell application "Finder"
mount volume "smb://username:password#server.domain.com/source/MAC/StandardApps"
duplicate file "SymantecEndpointProtection.zip" of folder "StandardApps" to folder "Desktop"
end tell
The error I get is "Can't set folder \"Desktop\" to folder \"StandardApps\"."
I'm sure I'm missing something simple, again I'm new to Applescript. Grateful for any help. I will provide any additional info you need.
Thanks in advance.

You need to use the complete file paths. For example, the path to the desktop folder in your user's account can be found by using path to desktop folder. Another easy way to see what a file path is would be to look at the result from a choose file dialog.

I was able to get it working by just mounting to the source share and changing the duplicate line to:
duplicate file "SymantecEndPointProtection.zip" of folder "StandardApps" of folder "Mac" of disk "source" to folder desktopPath

Related

Unable to find files in Documents from cmd

I am using Windows 10 and when I save a document I see the Documents folder it is being saved to on the left of the screen in the list under 'thisPC'. The bottom of that list has the C: drive. From Powershell, Bash or command prompt when I try to cd or locate the file I just saved I am told that it cannot find such a file. Why is my home directory the C: and not include the other files I mainly work with? I appreciate any help. Thank you
Command prompt works with files and folders.
Explorer works with virtual files or folders. Explorer is for users to easily find their stuff.
In Command prompt there is no such thing as This PC or anything under it. These are virtual things.
dir "%userprofile%\documents"
will list the files in your Documents folder if it is in the default location.

Where does this extra folder with \ 1/ came from

so I have external hdd hooked up with 2015 early mac book pro, usually when I want to access it I just type in cd /volumes/MAC -ls, will show all the files and folder in it.
Due to not ejecting properly, now I can't access that folder. Rather I see a new folder with same name like - cd /Volumes/MAC\ 1/. And I see all my files and folder in this folder.
Can anybody shed some light on it.
Thanks
This is probably happening due to a quirk of the way unix (and hence macOS) mounts volumes. They don't actually mount as folders, instead they mount over top of existing folders. Thus, when macOS detects that you've plugged in an external drive, it normally does something like this:
Figure out what the volume's "name" is
Create an empty folder named /Volumes/[volumename]
Mount the volume on that folder
When you unmount the volume, it does the reverse: it does the actual unmount, then deletes the folder it was mounted on. But if something goes wrong, and that folder doesn't get deleted, the leftover folder can cause this to happen when you attach the drive:
Figure out what the volume's "name" is
Try to create an empty folder named /Volumes/[volumename]... Oops, that already exists, better try something else.
Try to create an empty folder named /Volumes/[volumename 1]... Whew, that worked; we'll use that
Mount the volume on the /Volumes/[volumename 1] folder
Fortunately, the solution is pretty simple: check the leftover /volumes/MAC folder (or whatever it is using that name), make sure it doesn't contain anything important, delete it (or at least rename it), then cleanly unmount & remount your volume -- with the correct name available in /Volumes, it should mount without the " 1" suffix.
The termimal escape the space, thus you get MAC\ 1 for a folder named MAC 1.
Now as MAC was mounted, unmounted properly, then re-mounted, it was renamed from MAC to MAC 1

error "Finder got an error: The operation can’t be completed because there is already an item with that name." number -48

At work, I want to backup some Mac files to a Windows share and have created an AppleScript. It mounts the destination then creates a folder if it doesn't already exist. It then copies the contents of a local folder to this new folder on the destination. It then unmounts the destination
mount volume "smb://service.backup:<password>#server.domain.com/computer-backup"
set dest to result as alias
tell application "Finder"
if not (exists POSIX file "/Volumes/server.domain.com/computer-backup/Web") then make new folder with properties {name:"Web"} at "computer-backup"
duplicate items of folder "Macintosh HD:Library:Server:Web" to POSIX file "/Volumes/computer-backup/Web" with replacing
eject dest
end tell
The mount is fine. But if the folder "Web" exists on the destination then it errors - despite the "if not (exists" statement. I have a very similar script at home (with different usernames, passwords and server addresses) which works fine. I am pretty sure I have had this working at work as well (hence the use of POSIX) but not anymore.
I chose this route as a more granular alternative to TimeMachine and to show my boss I could write AppleScript :>)
Any help gratefully received.
All the best
John
Have you checked your 'Volumes' path? Path names usually does'nt contain the server name. I would go for (if not (exists POSIX file "/Volumes/computer-backup/Web") then make new folder with properties {name:"Web"} at "computer-backup") – tompaman Dec 27 '13 at 13:35

Where does it create the 7zip compressed files

I am using "7-zip 9.20" on "Windows 7".
If I compress a file in my "C" drive (ex: c:\myFolder ), using 7-zip, the output will be creating somewhere else. At this time, I cant find it even with a windows file search.
Does anyone know, where the default location and how can I change it...?
Finally I found the default location. This may be useful for some other as well.
C:\Users{user_name}\AppData\Local\VirtualStore
For anyone with this issue still using Windows 7, but updated to 7-Zip version of 16.04.
If you select the folder to archive >> Tools >> Options >> Folders tab, it will show the options for the Working Folder: System temp folder, current, or Specified, the last of which allows you to designate a path directory for every time you compress the file.
I thought the default was to the folder containing the files you try to archive.
When you select "Add to archive" there is a ... button beside the Archive name, where you can browse to the location you require.

Windows incorrectly copying files by filename when in a Special Folder

If I copy a file from a special folder to the clipboard, change the location that special folder points to, and try to paste the file to this new location, Windows complains with a Item Not Found error, seemingly trying to copy the file by the filename alone.
The way I change the special folder location is with this line of C++ code:
SHSetKnownFolderPath(FOLDERID_Desktop, 0, NULL, new_location);
And a refresh to see the effect immediately:
SHChangeNotify(0x8000000, 0x1000, NULL, NULL);
Steps to reproduce
Desktop pointing to C:\Users\BoppreH\Desktop
Copy the file music 1.mp3 from the Desktop (C:\Users\BoppreH\Desktop\music 1.mp3)
Change location of the Desktop special folder to D:\music
The Desktop now shows the musics from D:\music
Try to paste music 1.mp3 on the Desktop
It fails with Item Not Found, complaining it could not find the file at D:\music\music 1.mp3, when the file is still happily sitting at C:\Users\BoppreH\Desktop\music 1.mp3. If I paste the file in any other folder that is not the Desktop, it works fine.
I know this is a case of Doctor, it hurts when I do this, and that constantly changing the location of the Desktop is extremely unusual behavior, but this is a feature I've grown to love and this bug constantly bites me.
Is there some workaround for this issue?
Use some type of folder watcher control to detect when the Special Folders location has changed and check the clipboard for any file paths that refer to the old location and update them.
Or change the location of the Specials before you copy the file.

Resources