Hi All,
This is my Code:
var TemplateFile = File.openDialog("Choose the Template File");
var Root_Folder = Folder.selectDialog("Choose the Root Folder");
var copyPasteScript ="";
copyPasteScript = "tell application \"Finder\"\r";
copyPasteScript += "set dstFlChk to \""+TemplateFile+"\"\r";
copyPasteScript += "if exists file dstFlChk then\r";
copyPasteScript += "duplicate \""+TemplateFile+"\" to \""+Root_Folder+"\"\r";
copyPasteScript += "end if\r";
copyPasteScript += "end tell"
app.doScript(copyPasteScript, ScriptLanguage.applescriptLanguage);
It doesnt copy the file, I dont know what is the problem.
I also tried this,
1. copyPasteScript += "copy file (\""+TemplateFile +"\" as string) to folder (\"" + Root_Folder + " as string);
2. copyPasteScript += "copy file \""+TemplateFile +"\" to folder \"" + Root_Folder+"\"\r";
3. copyPasteScript += "duplicate file(\""+TemplateFile+"\" as string) to folder(\""+Root_Folder+"as string)\"\r";
What is the problem, plz give exact code
Thanks in Advance
Thanks Mark,
Actually my task is copy the file and paste it in a destination folder, but the thing is it should not modify the date of creation.
While doing copy paste in javascript it modifies the current date to that file. It should not happen to my case.
Plz help me.
Thanks in Advance
I had NOT noticed that behavior before now… Im rather rushed at the moment but your problem lies with the file paths passed by javascript… They are POSIX in style and unescaped so Finder will have no idea what to do with it. You can specify POSIX paths & files when working with Finder but you will need to change the AppleScript strings to do so…
Thanks Mark,
Can u help me to the exact code. This is my Code:
var TemplateFile = File.openDialog("Choose the Template File");
var Root_Folder = Folder.selectDialog("Choose the Root Folder");
var copyPasteScript ="";
copyPasteScript = "tell application \"Finder\"\r";
copyPasteScript += "set dstFlChk to \""+File(TemplateFile).fullName.toString()+"\" as string \r";
copyPasteScript += "set dstFld to \""+Root_Folder+"\" as string\r";
copyPasteScript += "copy file dstFlChk to folder dstFld\r";
copyPasteScript += "end tell";
app.doScript(copyPasteScript, ScriptLanguage.applescriptLanguage);
The error comes like this:
Can't set folder "~/Desktop/out" to file "~/Desktop.picture3.png"
Thanks in advance,
Actually my task is copy the file and paste it in a destination folder, but the thing is it should not modify the date of creation.
While doing copy paste in javascript it modifies the current date to that file. It should not happen to my case.
It's a little bit late to answer -- two weeks have already passed -- but here is a function that I wrote to deal with this problem, it works both for Mac and Windows.
Kasyan
function MoveFile(myFile, myFolder) {
if (!myFile instanceof File || !myFolder instanceof Folder || !myFile.exists || !myFolder.exists) return false;
var myMovedFile = new File(myFolder.absoluteURI + "/" + myFile.name);
if (File.fs == "Windows") {
var myVbScript = 'Set fs = CreateObject("Scripting.FileSystemObject")\r';
myVbScript += 'fs.MoveFile "' + myFile.fsName + '", "' + myFolder.fsName + '\\"';
app.doScript(myVbScript, ScriptLanguage.visualBasic);
}
else if (File.fs == "Macintosh") {
if (myFolder.fsName.match("Desktop") != null) {
var myMacFolder = myFolder.fsName.replace(/\//g, ":");
var myMacFile = myFile.fsName.replace(/\//g, ":");
var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'move to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';
}
else if (myFolder.fsName.match("Documents") != null) {
var myMacFolder = myFolder.fsName.replace(/\//g, ":");
var myMacFile = myFile.fsName.replace(/\//g, ":");
var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';
myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'move to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';
}
else {
var myMacFolder = myFolder.fullName.replace(/\//, "").replace(/\//g, ":");
var myMacFile = myFile.fullName.replace(/\//, "").replace(/\//g, ":");
var myAppleScript = 'tell application "Finder"\r';
myAppleScript += 'set myFolder to folder "' + myMacFolder + '"\r';
myAppleScript += 'set myFile to document file "' + myMacFile + '"\r';
myAppleScript += 'tell myFile\r';
myAppleScript += 'move to myFolder\r';
myAppleScript += 'end tell\r';
myAppleScript += 'end tell\r';
}
app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);
}
if (myMovedFile.exists) {
return true;
}
else {
return false;
}
}
I am having a surprising amount of trouble trying to get this script to work. (Error can't get file/folder) (-1728)
I'm sure there is something simple I am missing.
I've tried every combination of file and folder comannds i can think of...
Javascript- mac
var myFolder=Folder("/Volumes/myserver/inthis folder/"); //folder on a server that i want to send the file
var myFile= File("~/desktop/this folder/aaaaaa.indd");
... i know, this is sad
Actually, I can't get it to work for the shared network folder. It worked fine form folder to Folder on the same station.
The network folder is smb and should typically already be mounted. So I don't think I need to enter username and password?
can someone show me how to adapt that code.
Applescript is quite a different animal than javascript!
North America
Europe, Middle East and Africa
Asia Pacific