I work in a design agency and am trying to create an applescript that creates a folder structure and then afterwards copies files into specified folders that it creates.
I am a newbie to applescript and after hours of trawling the internet I have managed to create the bit that creates the folders. This allows me to create folders with specific job numbers then choose where to save it. This all works well. All I want to do now is to copy a couple of documents into folders that it creates.
This is what I have so far:
tell application "Finder"
activate
set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to POSIX path of (choose folder with prompt "Select client folder")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Reference") & "/" & quoted form of (jobNum & "_Briefs")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Reference") & "/" & quoted form of (jobNum & "_Copy")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Reference") & "/" & quoted form of (jobNum & "_Supplied")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Assets")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Old")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Final_Artwork")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Assets") & "/" & quoted form of (jobNum & "_Purchased_Images")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Assets") & "/" & quoted form of (jobNum & "_Non_Purchased_Images")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_In_Situ") & "/" & quoted form of (jobNum & "_JPG's")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_In_Situ") & "/" & quoted form of (jobNum & "_PSD's")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Artwork_&_Design") & "/" & quoted form of (jobNum & "_Id")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Artwork_&_Design") & "/" & quoted form of (jobNum & "_Ai")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Artwork_&_Design") & "/" & quoted form of (jobNum & "_PS") & "/" & quoted form of (jobNum & "_PSDs")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Artwork_&_Design") & "/" & quoted form of (jobNum & "_PS") & "/" & quoted form of (jobNum & "_JPGs")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Artwork_&_Design") & "/" & quoted form of (jobNum & "_Presentation_Boards")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_C4D") & "/" & quoted form of (jobNum & "_Assets")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_C4D") & "/" & quoted form of (jobNum & "_Renders")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_C4D") & "/" & quoted form of (jobNum & "_Visuals")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Creative") & "/" & quoted form of (jobNum & "_Mac_Scamps")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_Creative") & "/" & quoted form of (jobNum & "_Scamps")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & "_" & jobName) & "/" & quoted form of (jobNum & "_For_Client")
end tell
E.g. I want to copy an InDesign file into the "presentation boards" folder and copy a pdf into the reference file which would then open once the applescript had finished.
Any help would be much appreciated.
Thanks
You can set all the folders as variables and feed it an input folder to move files and sort them. Can't get too specific or you will run into an issue of it won't work for other jobs. I would go like this.
set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to POSIX path of (choose folder with prompt "Select client folder")
set InputFolder to (choose folder with prompt "Select client folder") as alias
tell application "Finder"
set FileList to get every item of folder InputFolder
set FolderVariable to make new folder at Desination with properties{Name:"folderName" & jobName"}
set FolderVariable2 to make new folder at Desination with properties{Name:"folderName" & jobName"}
repeat with CurrentFile in FileList
if (name of CurrentFile) contains "SomeIdentifier" then
move file CurrentFile to folder FolderVariable
else if (name of CurrentFile) contains "SomeotherIdentifier" then
move file CurrentFile to folder FolderVariable2
end if
end tell
Add more ifs if you have different identifiers
Related
I am trying to path multiples variables to an application using vbscript but it is not working for me and I do not know how to fix:
Set SH = WScript.CreateObject("WScript.Shell")
Set colFiles = objFolder.Files
For Each objFile in colFiles
SH.Run ".\Resizer.exe /resize /overwrite /width: " & strResize & objFile.Path & objFile.Path,,True
Next
Resizer.exe will resize objFile.path (example: D:\pic.jpg) with strReszie width and will save it again as objFile.path
Where is the problem?
Two things:
You're not putting any spaces between your params:
strResize & objFile.Path & objFile.Path
should be:
strResize & " " & objFile.Path & " " & objFile.Path
Make sure you surround any file paths with quotes, in case they contains spaces:
strResize & " " & Chr(34) & objFile.Path & Chr(34) & " " & Chr(34) & objFile.Path & Chr(34)
I have a problem. I need to throw some synchronized commands in vbscript (one Run method, Delete one and moveFile one) in every cycle to my loop. I don't know how I do it.
My code is that:
Public Function UnificarCRIs(ByVal path, ByVal FICRIEC, ByVal sessio, ByVal CIBAA)
Dim objFile, objCurrentFolder, filesys, origenFitxers
Dim FileName, WshShell
On error resume next
Set filesys = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objCurrentFolder = filesys.getFolder(path)
For Each objFile In objCurrentFolder.Files
FileName = objFile
If (right(FileName, 4) = ".cri") Then
If filesys.FileExists(path & FICRIEC & sessio) Then
'WshShell.Run ("copy " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp")
WshShell.run ("cmd /K " & "copy /Y " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp",8,TRUE)
Set WshShell = Nothing
filesys.DeleteFile path & FICRIEC & sessio
'filesys.MoveFile path & FICRIEC & sessio & "_tmp", path & FICRIEC & sessio
Else
WshShell.run "cmd /K " & "copy /Y " & FileName & " " & path & FICRIEC & sessio,8,TRUE
Set WshShell = Nothing
End If
End If
Next
End Function
Read the docs for .Run completely and reflect on the bWaitOnReturn parameter.
Apology:
Sorry, I didn't read your code carefully enough. The .Run should wait. But I see that you use a global On Error Resume Next and param list () in
WshShell.run ("cmd /K " & "copy /Y " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp",8,TRUE)
What happens, when you remove those mistakes? Are you sure, that you have a usable WshShell in the second pass thru the loop?
I have an issue with reloading a QlikView document. When I execute a batch file with the command:
"C:\Program Files (x86)\QlikView\Qv.exe" /r "C:\QlikViewMount\reloadvictim.qvw"
the document reloads fine.
But, when I put it into a QlikView Macro (VBScript), it is giving me 'Unknown command line option'.
This is what I used:
strCommand = chr(34) & "C:\Program Files (x86)\QlikView\Qv.exe" & chr(34) & "/r" & chr(34) & "C:\QlikViewMount\reloadvictim.qvw" & chr(34)
The syntax
strCommand = chr(34) & " " ....
makes me think that you want to do a reload of your data when you are in qlikview.
Why not press CTRL+R?
It appears that your command line is missing a couple of spaces either side of your /r parameter, the below should solve your problem:
strCommand = chr(34) & "C:\Program Files (x86)\QlikView\Qv.exe" & chr(34) & " /r " & chr(34) & "C:\QlikViewMount\reloadvictim.qvw" & chr(34)
I need a script that could ran and pull information from any drive on a windows operating system (Server 2003), listing all files and folders which contain the following fields:
Full file path (e.g. C:\Documents and Settings\user\My Documents\testPage.doc)
File type (e.g. word document, spreadsheet, database etc)
Size
When Created
When last modified
When last accessed
Any help is appreciated.
Thanks
try this vbscript
Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFolder = objArgs(0)
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
If objDIR <> "\System Volume Information" Then
For Each eFolder in objDIR.SubFolders
Go eFolder
Next
End If
For Each strFile In objDIR.Files
WScript.Echo "Full Path: " & strFile.Path
WScript.Echo "File Size(bytes): " & strFile.Size
WScript.Echo "File Date modified: " & strFile.DateLastModified
WScript.Echo "File Date Created: " & strFile.DateCreated
WScript.Echo "File Date accessed: " & strFile.DateLastAccessed
Next
End Sub
on command line
c:\test> cscript //nologo myscript.vbs c:\
To save the results to a csv file modify ghostdog74's code as follows.
Set objFS=CreateObject("Scripting.FileSystemObject")
WScript.Echo Chr(34) & "Full Path" &_
Chr(34) & "," & Chr(34) & "File Size" &_
Chr(34) & "," & Chr(34) & "File Date modified" &_
Chr(34) & "," & Chr(34) & "File Date Created" &_
Chr(34) & "," & Chr(34) & "File Date Accessed" & Chr(34)
Set objArgs = WScript.Arguments
strFolder = objArgs(0)
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
If objDIR <> "\System Volume Information" Then
For Each eFolder in objDIR.SubFolders
Go eFolder
Next
End If
For Each strFile In objDIR.Files
WScript.Echo Chr(34) & strFile.Path & Chr(34) & "," &_
Chr(34) & strFile.Size & Chr(34) & "," &_
Chr(34) & strFile.DateLastModified & Chr(34) & "," &_
Chr(34) & strFile.DateCreated & Chr(34) & "," &_
Chr(34) & strFile.DateLastAccessed & Chr(34)
Next
End Sub
Then call it from the command line like this.
c:\test> cscript //nologo myscript.vbs "c:\" > "C:\test\Output.csv"
I need a script that can run and pull information from any drive on a Windows operating system (Windows Server 2003), listing all files and folders which contain the following fields: The server is quite big and is within our domain.
The required information is:
Full file path (e.g. C:\Documents and Settings\user\My Documents\testPage.doc)
File type (e.g. word document, spreadsheet, database etc)
Size
When Created
When last modified
When last accessed
Also the script will need to convert that data to a CSV file, which later on I can modify and process in Excel. I can imagine that this data will be huge but I still need it. I am logged in as an administrator on the server and the script will need to also process protected files. As in previous posts I have read that the script will stop if such files are processed. I need to make sure that not a single file is skipped.
Please note I have asked this question before but still have not got a working script.
This is the script I got so far, file Test.vbs:
Set objFS=CreateObject("Scripting.FileSystemObject")
WScript.Echo Chr(34) & "Full Path" &_
Chr(34) & "," & Chr(34) & "File Size" &_
Chr(34) & "," & Chr(34) & "File Date modified" &_
Chr(34) & "," & Chr(34) & "File Date Created" &_
Chr(34) & "," & Chr(34) & "File Date Accessed" & Chr(34)
Set objArgs = WScript.Arguments
strFolder = objArgs(0)
Set objFolder = objFS.GetFolder(strFolder)
Go (objFolder)
Sub Go(objDIR)
If objDIR <> "\System Volume Information" Then
For Each eFolder in objDIR.SubFolders
Go eFolder
Next
End If
For Each strFile In objDIR.Files
WScript.Echo Chr(34) & strFile.Path & Chr(34) & "," &_
Chr(34) & strFile.Size & Chr(34) & "," &_
Chr(34) & strFile.DateLastModified & Chr(34) & "," &_
Chr(34) & strFile.DateCreated & Chr(34) & "," &_
Chr(34) & strFile.DateLastAccessed & Chr(34)
Next
End Sub
I am currently using the command-line to run it:
c:\test> cscript //nologo Test.vbs "c:\" > "C:\test\Output.csv"
The script is not working. I don't know why.
Properly passing cmd-line args to vbs when using Cscript
-Modify the cmd-line statement as follows (drop the ">")
c:\test> cscript //nologo Test.vbs "c:\" "C:\test\Output.csv"
-Next inside the script you can access the cmd-line parameters as follows
strFolder = WScript.Arguments.Item(0)
strFile = WScript.Arguments.Item(1)
I hope now you can access the files and list them properly in the csv-file. :-)
GoodLUCK!!
- CVS