Moving .plist from usb drive to local disk using applescript - macos

I've been trying to figure this one out for a while now, and I've hit a bit of a wall.
I have quite a few Macs in my environment, and for inventory purposes I need to copy a file named "Department-Info.plist" from a USB Drive to the following location on the hard drive
Macintosh HD:Library:Application Support:Dell:KACE:
I've come up with a couple of solutions that I thought might work, and believe I'm on the right track. However, I'm not getting the result I'm looking for.
Below is what I've come up with thus far, but I need to complete this task:
tell application "Finder"
activate
set FileToMove to "VOLUMES:DELL KACE:Mac:Department-Info.plist"
set FinalLoc to "Macintosh HD:Library:Application Support:Dell:KACE:"
copy file FileToMove to FinalLoc
end tell
I receive this error message when running this script:
I've also tried using this variation of the script:
tell application "Finder"
activate
set name of document file "Department-Info.plist" of folder "Mac" of disk "DELL KACE" to "Department-Info.plist"
set FinalLoc to "Macintosh HD:Library:Application Support:Dell:KACE:"
copy "Department-Info.plist" to FinalLoc
end tell
However, this yields the following result.
I wondered if anyone could point me in the right direction, or provide resources that I may have missed.

First of all, the command copy assigns a value to a variable, it does not copy files
The correct code is
tell application "Finder"
-- activate is not needed
set FileToMove to "DELL KACE:Mac:Department-Info.plist"
set FinalLoc to "Macintosh HD:Library:Application Support:Dell:KACE:"
duplicate file FileToMove to folder FinalLoc
end tell
However consider that you might not have sufficient access privileges to copy the file.
In this case you need to use the shell to enter an admin password:
do shell script "cp '/Volumes/DELL KACE/Mac/Department-Info.plist' '/Library/Application Support/Dell/KACE/'" with administrator privileges

Related

Applescript to rename a file in the applications folder

I'm trying to use a script to rename a text file in the applications folder. I'm trying the following
tell application "Finder"
set name of file "File.txt" of applications folder to "File.txt.OFF"
end tell
But this gives an error:
Can’t get file "Text.txt" of applications folder.
Its definitely in there and called that (it's a copy and paste). I then tried removing the folder bit:
set name of file "File.txt" of applications to "File.txt.OFF"
But got another error:
Finder got an error: Can’t set every application to "Text.txt.OFF".
Any help would be much appreciated.
Cheers
applications folder in Finder terminology does not point to the standard folder /Applications. It seems to be a legacy reference to some pre OS X item.
Try this, but you might not have permission to change the name and you are discouraged anyway from putting arbitrary data like text files into /Applications
set applicationsFolder to path to applications folder
tell application "Finder"
set name of file "File.txt" of applicationsFolder to "File.txt.OFF"
end tell
or use System Events
tell application "System Events"
set name of file "File.txt" of applications folder of local domain to "File.txt.OFF"
end tell

Copy a file from a network folder using applescript

Iam very new to applescript and am currently trying to copy a file from a network share. I have an iMac server on my network and this script will be distributed to all the mac computers connected to it.
Below is the code i have at the moment :-
set mycopypath to "Volumes:Work Basket:LabRat:LabRat For Client Side.xlsx" as alias
--set mycopypath to choose file
tell application "Finder" to set startup_Disk to (name of startup disk)
set mypastepath to startup_Disk & ":Users:Arjun:Desktop:" as alias
tell application "Finder" to duplicate mycopypath to mypastepath with replacing
In the above code , 'Work Basket' in the 'mycopypath' is the shared network folder. Currently when i run this code i get an error stating - File Volumes:Work Basket:LabRat:LabRat For Client Side.xlsx wasn’t found.
But when i use the commented out part set mycopypath to choose file it works fine. Also, if i use the above code to copy paste a file from one location to another on the local computer itself, it works fine. The network folder "Work Basket" is mounted in both cases.
I'v been at it for quite a few hours and must have tried many combinations of file paths but haven't been able to find a solution.Any help will be great.
Try the following solution:
When you only uncomment the set mycopypath to choose file and comment the rest, you will get the correct path as a result in the bottom half of Script Editor. (See red arrow in screenshot).
After that copy that path to the set mycopypath to "" part and restore the original comments. This should work.
EDIT
I believe this is how to mount a network disk:
tell application "Finder" to mount volume "Your disk path/name"
EDIT 2
Mounting a network disk with user and pass:
mount volume "afp://192.168.200.1/" as user name "your username" with password "your password"
Unlike POSIX paths where a path starts always with a / representing the startup volume and a path to an external volume starts with /Volumes, HFS paths (colon separated) start always with a disk name.
This is a shorter version of your code, the Finder has a property desktop
set mycopypath to "Work Basket:LabRat:LabRat For Client Side.xlsx" as alias
tell application "Finder" to duplicate mycopypath to desktop with replacing

Applescript Error: Finder got an error: Can’t get folder "~/Library/Services"

Here is my code:
tell application "Finder"
move POSIX file "/Volumes/Toggle Desktop Icons/Toggle Desktop Icons/Install Files/Hide Icons.workflow" to folder "~/Library/Services"
end tell
And it always gets this error: Can’t get folder "~/Library/Services".
Any help? This also needs to work on any mac I run the code on. Without changing the code
Thanks.
There is a system property path to home folder that you could use. And for simplicity sake use the native mac HFS path delimiter ":" to reference the rest of your path.
Try this (adding back in your full source path),
tell application "Finder"
move POSIX file "/Volumes/.../Hide Icons.workflow" to folder (((path to home folder) as text) & "Library:Services")
end tell

move a file in finder with applescript

I just want to move an image from one folder to the other, replacing the one that's already in there:
tell application "Finder"
copy file "/Users/xx/Documents/img.jpg" to folder "/Users/xx/Documents/State"
end tell
When I run it, I get an error message saying
Finder got an error: Can’t set folder [path] to file [path]"."number
-10006 from folder [path]
Please help me!
Try:
tell application "Finder"
duplicate POSIX file "/Users/xx/Documents/img.jpg" to POSIX file "/Users/xx/Documents/State" with replacing
end tell
Or
tell application "Finder"
move POSIX file "/Users/xx/Documents/img.jpg" to POSIX file "/Users/xx/Documents/State" with replacing
end tell
As #adayzdone notes, the error appears because you're using a Posix-style path without declaring it.
Another approach is to use colon-separated HFS paths, like so:
move file "Macintosh HD:Users:xx:Documents:img.jpg" ¬
to "Macintosh HD:Users:xx:Documents:State:" with replacing
With colon-separated paths you need to include the whole thing, including the volume name (I'm assuming Macintosh HD here), otherwise it'll throw our good friend error 10,006.
It helped me:
set theSource to POSIX file "/Users/xx/Documents/img.jpg"
set theDest to POSIX file "/Users/xx/Documents/State"
tell application "Finder"
move theSource to folder theDest with replacing
end tell

AppleScript Droplet on DMG not working

Hey I have the following AppleScript saved as a Droplet.
It is saved on a DMG file like this one http://dl.dropbox.com/u/1839051/TestDMG.dmg
The Problem is, while some can drag the template onto the Droplet and have it working, when I try to drag the template onto the droplet the crossed-out circle-symbol shows up indicating that this action is not possible. Nothing happens, the file is not copied.
Does anyone have any idea why I have this problem and how it can be fixed?
Thanks in advance guy.
on open thefiles
set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder
tell application "Finder"
duplicate thefiles to outputFolder
end tell
end open
Rather than using a droplet and having the user to drag the files onto the droplet, why not just make an installer so the user only has to double-click the installer? It would be easier and also probably avoid your problem. I also added some error handling in your code because it's just prudent to do that with shipping code. We also tell the user what happened.
NOTE: you also had an error in your code. The outputFolder is a string. The Finder requires a file specifier. To make the string into a specifier you add either the word "file" or "folder" in front of the string path. Your code may have worked but the proper way to write it is with a specifier. Other applications may not take the string path but they will all take the specifier... so get in the habit of using them instead of strings.
try
-- create the output folder if necessary
set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder
-- find the templates on the dmg disk
set myPath to path to me
tell application "Finder"
set myContainer to container of myPath
set templateFiles to (files of myContainer whose name extension is "template") as alias list
end tell
-- copy the templates to the output folder
-- NOTE: the script will error if any of the templates already exist
-- therefore we use a repeat loop and duplicate each file separately with a try block
-- around it to avoid errors in case some templates have already been installed.
tell application "Finder"
repeat with aTemplate in templateFiles
try
duplicate aTemplate to folder outputFolder
end try
end repeat
end tell
-- tell the user everything was OK
tell me to activate
display dialog "The templates were successfully installed! You may now use them in Pages." buttons {"OK"} default button 1 with title "Templates Installer" with icon note
on error
tell me to activate
display dialog "There was an error installing the templates. Please manually install them by copying them to the following folder." & return & return & (POSIX path of outputFolder) buttons {"OK"} default button 1 with title "Templates Installer"
end try
This looks to be a permissions issue, and I have to wonder if the differential between those who can and those who can't have something to do with which OS they are running. I'm running Mac OS 10.6 as an administrator and I was unable to perform the action in the DMG. But I was able to perform the action if I dragged both files out of the DMG and onto my Desktop.
If you need to install files in specific locations to the hard drive to support your project, then I would recommend making an installer (and a matching uninstaller as well) as opposed to the setup you have presented.

Resources