The variable thedData is not defined. (-2753)
How to fix?
set default_path to "Users/mrvisuals/Desktop"
set nuntaNume to text returned of (display dialog "Nunta Nume:" default answer "")
set nuntaData to text returned of (display dialog "Nunta Data:" default answer "")
set folderpath to (choose folder with prompt "Select Folderul Nunti" default location default_path)
set newnuntaFolder to my newFold(nuntaNume, nuntaData, folderpath)
on newFold(theNume, theData, thefolder)
set subNumeList to {"1.Steps Nunta", "2.STD", "3.TTD", "4.Album", "5.Blog", "6.Des"}
set itemCount to count of subNumeList
tell application "Finder"
set newnuntaFolder to (make new folder at thefolder with properties {name:thedData & "_" & theNume})
repeat with i from 1 to itemCount
set thisFolder to make new folder at newnuntaFolder with properties {name:"" & item i of subNumeList}
if item i of subNumeList contains "1.Steps Nunta" then
make new folder at thisFolder with properties {name:"1.Pregatiri"}
make new folder at thisFolder with properties {name:"2.First Look"}
make new folder at thisFolder with properties {name:"3.Primarie"}
make new folder at thisFolder with properties {name:"4.Biserica"}
make new folder at thisFolder with properties {name:"5.Sedinta"}
make new folder at thisFolder with properties {name:"6.Sala"}
end if
end repeat
end tell
end newFold
Your handler defines the parameter as theData:
on newFold(theNume, theData, thefolder)
but your handler later refers to it as thedData:
set newnuntaFolder to (make new folder at thefolder with properties {name:thedData & "_" & theme})
In that line, you need to change thedData to theData
Related
Im looking for some help with an addition to a larger apple script, ive seen lots of similar queries but none that quite fit the bill, so if anyone can help or direct me to an answer it would be a huge help,
I wanting to follow this general premise
`“Choose Name” default answer “”
set ChosenName to text returned of result
set ImagesFolder to (choose folder with prompt “Choose Images Folder:”)`
The bit im struggling with
if the ImagesFolder contains a folder named “Image Set 1” then
look through the folder “Images Set 1” and rename the contents using this logic
if file name conatins 0001_ rename file to ChosenName & “front”
if file name conatins 0002_ rename file to ChosenName & “Back”
if file name conatins 0003_ rename file to ChosenName & “Top”
if file name conatins 0004_ rename file to ChosenNamet & “Bottom”
else
if the ImagesFolder contains a folder named “Image Set 2” then
look through the folder images 2 and rename the content using this logic
if file name conatins 0001_ rename file to ChosenName & “F”
if file name conatins 0002_ rename file to ChosenName & “B”
if file name conatins 0003_ rename file to ChosenName & “T”
if file name conatins 0004_ rename file to ChosenNamet & “B”
(The unqiue characters im using to identify these files are always the last characters if this helps)
Thanks
P
This script does what you need. You need to extend it to also manage the "Image Set 2" folder and its extension name, but It will be quite easy to just duplicate what's inside the Tell "Finder" block.
Because you have multiple folder, I used a sub-routine to process your folder, each time calling new rule. For instance the 1st rule is to process "Image Set 1, search for 0001,0002,0003,0004 and replace each with Front,Back,Top, Bottom.
The rule 2 is to process "Image Set 2, search for 0001,0002,0003,0004 and replace each with F,B,T, B.
The first part build the rules. The script itself is reduced to a loop through each rule, calling the sub-routine "Process_SubFolder" with the 3 variables: sub folder name, current targets and new names.
(*
Define record Rule, made of 3 variables :
NFolderNFolder: the name of sub-folder
NSource : the list of part of file names to be processed
NDest : the list of new names. This list MUST count same number of items as NSource
All rules are added into ListRules
*)
global ChosenName, ImagesFolder -- mandatory to use in the sub-routine
set Rule to {NFolder:"Image Set 1", NSource:{"0001", "0002", "0003", "0004"}, NDest:{"Front", "Back", "Top", "Bottom"}}
set ListRules to {Rule}
set Rule to {NFolder:"Image Set 2", NSource:{"0001", "0002", "0003", "0004"}, NDest:{"F", "B", "T", "B"}}
set ListRules to ListRules & {Rule}
set R to display dialog "Enter a name" default answer ""
set ChosenName to text returned of R
if ChosenName is "" then return -- no name selected, end of script
set ImagesFolder to choose folder with prompt "Choose Images Folder:"
repeat with aRule in ListRules
Process_SubFolder(NFolder of aRule, NSource of aRule, NDest of aRule)
end repeat
-- end of main script
on Process_SubFolder(LFolder, LSource, LDest)
tell application "Finder"
set SubFolder to (ImagesFolder as string) & LFolder
if folder SubFolder exists then
set FileList to every file of folder SubFolder -- get all files of Images Set 1
repeat with aFile in FileList -- loop through each file
set FName to name of aFile
set NewName to ""
-- Manage extension of the file
if name extension of aFile is "" then
set NewExt to ""
else
set NewExt to "." & name extension of aFile
end if
repeat with I from 1 to count of LSource --loop trhough each source of the rule
if FName contains (item I of LSource) then set NewName to ChosenName & (item I of LDest) & NewExt
end repeat
if NewName is not "" then set name of aFile to NewName -- only if name must be changed !
end repeat -- loop through files of LFolder
end if -- folder exists
end tell
end Process_SubFolder
With this structure, you can add as many rules as you want !
Of course, I assume that you will never get twice same names in sub folder ! It is not the case in Image Set 2, where you will have 2 files with new name = ChosenNameB : it will create an error !!
Good day,
I have used multiple sources to crete a workflow for creating folder structure which creates sub folders. The problem i am having is with the section that creates sub-folders under 'MyCompany" subfolder.
tell application "Finder"
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
set Customer to text returned of (display dialog "Customer Name:" default answer "Customer")
set loc to choose folder "Choose Parent Folder Location"
set incomingDate to (current date)
set yr to year of incomingDate as text
set mo to (month of incomingDate as number) as text
if ((length of mo) = 1) then
set mo to "0" & mo
end if
set dy to day of incomingDate as text
if ((length of dy) = 1) then
set dy to "0" & dy
end if
set newfoldername to mo & dy & yr & "-" & JobName
set customer2 to Customer & "-" & JobName
set newfo to make new folder at loc with properties {name:newfoldername}
make new folder at newfo with properties {name:"Caps"}
set doc to make new folder at newfo with properties {name:"Document"}
make new folder at doc with properties {name:"Customer"}
make new folder at doc with properties {name:"Lic"}
make new folder at doc with properties {name:"Deliverable"}
make new folder at doc with properties {name:"Mfg"}
make new folder at doc with properties {name:"Validation"}
set mdc to make new folder at newfo with properties {name:"MyCompany"}
make new folder at mdc with properties {name:"Quotes"}
make new folder at mdc with properties {name:"SoW"}
make new folder at mdc with properties {name:"Private"}
set cfg to make new folder at newfo with properties {name:"Config"}
make new folder at cfg with properties {name:"Sites"}
make new folder at cfg with properties {name:"Worksheet"}
make new folder at cfg with properties {name:"Backups"}
make new folder at cfg with properties {name:"Logs"}
set diag to make new folder at newfo with properties {name:"Diagrams"}
make new folder at diag with properties {name:"Screenshots"}
make new folder at diag with properties {name:"Visio"}
make new folder at diag with properties {name:"Logos"}
make new folder at newfo with properties {name:"Scripts"}
end tell
tell application id "com.evernote.Evernote"
create note with text "via Apple WorkFlow" title customer2 notebook "Inbox"
end tell
What I would like to have is:
mmddyy-%currenttime%-JobName
Document
MyCompany
Quotes
SoW
Private
Any help would be greatly appreciated.
Not sure if this is the cleanest way, but it worked for me:
-- Sets up the JobName, CustomerName and location by asking the user
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
set Customer to text returned of (display dialog "Customer Name:" default answer "Customer")
set loc to choose folder "Choose Parent Folder Location"
-- Sets up the date variables
set incomingDate to (current date)
set yr to year of incomingDate as text
set mo to (month of incomingDate as number) as text
if ((length of mo) = 1) then
set mo to "0" & mo
end if
set dy to day of incomingDate as text
if ((length of dy) = 1) then
set dy to "0" & dy
end if
-- Sets the filename to be used concatinated with date
set newfoldername to mo & dy & yr & "-" & JobName
set customer2 to Customer & "-" & JobName
tell application "Finder"
--Parent Directory Structure
set dir_1 to make new folder at loc with properties {name:newfoldername}
set dir_2 to make new folder at dir_1 with properties {name:"Caps"}
set dir_3 to make new folder at dir_1 with properties {name:"Configs"}
set dir_4 to make new folder at dir_1 with properties {name:"Diagrams"}
set dir_5 to make new folder at dir_1 with properties {name:"Documents"}
set dir_6 to make new folder at dir_1 with properties {name:"Scripts"}
-- Sub-Folder structure
set sub_3_1 to make new folder at dir_3 with properties {name:"Backups"}
set sub_3_2 to make new folder at dir_3 with properties {name:"Logs"}
set sub_3_3 to make new folder at dir_3 with properties {name:"Sites"}
set sub_3_4 to make new folder at dir_3 with properties {name:"Worksheets"}
set sub_4_1 to make new folder at dir_4 with properties {name:"Logos"}
set sub_4_2 to make new folder at dir_4 with properties {name:"Screenshots"}
set sub_4_3 to make new folder at dir_4 with properties {name:"Network Diagrams"}
set sub_5_1 to make new folder at dir_5 with properties {name:"Customer"}
set sub_5_2 to make new folder at dir_5 with properties {name:"Deliverable"}
set sub_5_3 to make new folder at dir_5 with properties {name:"License"}
set sub_5_4 to make new folder at dir_5 with properties {name:"Certificates"}
set sub_5_5 to make new folder at dir_5 with properties {name:"MyCompany"}
set sub_5_6 to make new folder at dir_5 with properties {name:"Validation"}
-- Creates sub-folders under \MyCompany
set sub2_5_1 to make new folder at sub_5_5 with properties {name:"BoMs"}
set sub2_5_2 to make new folder at sub_5_5 with properties {name:"Quotes"}
set sub2_5_3 to make new folder at sub_5_5 with properties {name:"Private"}
set sub2_5_4 to make new folder at sub_5_5 with properties {name:"SoW"}
-- Set variable to be used by Evernote
set custfldr to the loc as text
end tell
tell application "Finder"
set the clipboard to the loc as text
end tell
tell application id "com.evernote.Evernote"
create note with text custfldr title customer2 notebook "Inbox"
end tell
This gives me the desired outcome.
This code will duplicate a Microsoft Outlook message to the drafts folder:
tell application "Microsoft Outlook"
...
-- find the template give an ID
set theTemplate to message id theID
-- duplicate the message
duplicate theTemplate to drafts
...
end tell
I need a reference to the duplicate for additional processing.
Unfortunately, this doesn't work:
...
-- this will create a duplicate
set theDuplicate to (duplicate theTemplate to drafts)
-- produces an error that reads "The variable theDuplicate is not defined."
display dialog (subject of theDuplicate) & " [" & (id of theDuplicate) & "]"
How do I get a reference to the message that was just duplicated? Its ID would be a satisfactory alternative.
There must be a better way but...
--For Testing
set theID to 39110
tell application "Microsoft Outlook"
set oldIds to my getDraftIds()
-- find the template give an ID
set theTemplate to message id theID
--duplicate the message
duplicate theTemplate to drafts
set newIds to my getDraftIds()
set duplicatedMessage to message id (my findNewID(oldIds, newIds))
end tell
on getDraftIds()
set messageIDs to {}
tell application "Microsoft Outlook"
set draftFolders to (every folder whose name = "Drafts")
repeat with dFolder in draftFolders
set messageIDs to messageIDs & id of dFolder's messages
end repeat
end tell
end getDraftIds
on findNewID(oldList, newList)
repeat with mID in newList
if mID is not in oldList then return mID
end repeat
end findNewID
I guess the duplicate method is pretty limited in this regard. I tried the more generic copy method too - the message is copied, but again no ID is returned.
Here's another possible way to do this with no repeat loops:
Create a new, temporary category
Mark the original message with the new category
Duplicate - the duplicate message will also be marked with the category
search for messages marked with the temporary category - you should only get two - the original and the duplicate
Delete the temporary category
Here is the code (rather unfinished):
tell application "Microsoft Outlook"
try
set tempCategory to category "Temporary Category"
on error number -1728
set tempCategory to (make new category with properties {name:"Temporary Category"})
end try
set messageList to selected objects
set origMsg to item 1 of messageList
display dialog "Original Message ID: " & id of origMsg
set msgCat to category of origMsg
set end of msgCat to tempCategory
set category of origMsg to msgCat
duplicate origMsg to drafts
delay 1 -- sigh, it seems to take a bit of time before the category markings are reflected in the spotlight DB
--set msgList to messages whose category contains tempCategory
set currentIdentityFolder to quoted form of POSIX path of (current identity folder as string)
set tempCatMsgs to words of (do shell script "mdfind -onlyin " & currentIdentityFolder & " 'com_microsoft_outlook_categories == " & id of tempCategory & "' | xargs -I % mdls -name com_microsoft_outlook_recordID '%' | cut -d'=' -f2 | sort -u | paste -s -")
if item 1 of tempCatMsgs is (id of origMsg) as text then
set dupMsgId to item 2 of tempCatMsgs
else
set dupMsgId to item 1 of tempCatMsgs
end if
delete tempCategory
display dialog "Original Message ID: " & id of origMsg & return & "Duplicate Message ID: " & dupMsgId
end tell
I thought it would be easier to find messages with a given category using the OL dictionary, but instead had to resort a spotlight search. I'm sure there is a better way to do this.
Also adding a category to a message was harder than I though - again I'm sure this can be done more efficiently.
-- create a temporary folder to hold duplicates
on createFolder(theName)
tell application "Microsoft Outlook"
set theFolder to make new mail folder with properties {name:theName}
end tell
end createFolder
-- find folder by name
on findFolder(theName)
tell application "Microsoft Outlook"
set theFolder to make new mail folder with properties {name:theName}
end tell
end findFolder
-- duplicate the message and get a reference
on duplicateIt(theID)
set theDestination to findFolder("foo bar")
tell application "Microsoft Outlook"
--find the template
set theTemplate to message id theID
-- duplicate it to the temporary location
(duplicate theTemplate to theDestination)
-- get the first item in the folder
set theDuplicate to item 1 of theDestination
-- do something with it
...
end tell
end duplicateIt
A client has a massive WordPress uploads folder with 7 or 8 size versions of each file.
I'm looking to filter out all images that have -NNNxNNN as part of the file name - "NNN" being any number. For eg:
Originally uploaded file: 7Metropolis711.jpg
Example resized version of same file: 7Metropolis711-792x373.jpg
I'm using Automator for this, and I'm just looking for the Applescript to filter out those files from the inputted folder of files.. IE:
Here is another approach:
on run {input}
set newList to {}
repeat with aFile in input
tell application "System Events" to set fileName to name of aFile
try
set variableName to do shell script "echo " & quoted form of fileName & " | grep -Eo [0-9]{3}x[0-9]{3}"
on error
set end of newList to (aFile's contents)
end try
end repeat
return newList
end run
Try this. You can see a handler "isFormatNNNxNNN(fileName)" which tests the file name for your format. Obviously remove the first 2 lines of the code. They're used so I could test this in AppleScript Editor. They should equal your input variable in Automator.
EDIT: based on your comments I modified the script to account for more than one "-" in the file name. Now I start looking at the text in front of the file extension since I assume your format is the last characters in the file name.
It didn't work in Automator because you have to put "on run {input, parameters}" around the code. I have done that now so just copy/paste this into automator.
on run {input, parameters}
set newList to {}
repeat with aFile in input
if not (my isFormatNNNxNNN(aFile)) then set end of newList to (contents of aFile)
end repeat
return newList
end run
on isFormatNNNxNNN(theFile)
set theBool to false
try
tell application "System Events"
set fileName to name of theFile
set fileExt to name extension of theFile
end tell
set endIndex to (count of fileExt) + 2
set nameText to text -(endIndex + 7) thru -endIndex of fileName
if nameText starts with "-" then
if character 5 of nameText is "x" then
-- test for numbers
text 2 thru 4 of nameText as number
text 6 thru 8 of nameText as number
set theBool to true
end if
end if
end try
return theBool
end isFormatNNNxNNN
EDIT: regulus6633 has made a script that's a lot better than my outline below, it works perfectly IF you're template file isn't completely empty (I think this caused an error originally). Thanks!
This script is supposed to (1) copy a x.txt to a specific folder rename it to new_name, (2) open it, (3) paste "new_name" in all caps, and (4) insert ":" followed by return & return. The first part is working, but I'm having trouble figuring out (2), (3) and (4). The code I've written so far is pasted below.
tell application "Finder"
display dialog "new_name_dialogue" default answer " "
set new_name to (text returned of result)
set Selected_Finder_Item to (folder of the front window) as text
duplicate file "Q:x:7:n7:GTD scripting:template folder:x.txt" to "Q:X:7:SI:SIAG1"
set Path_Of_X to "Q:X:7:SI:SIAG1:" & "x.txt" as string
set name of file Path_Of_X to (new_name as text) & ".txt"
#[something that let's me open the file is needed here]
#[something that pastes "new_name" & ":" in ALL CAPS]
#[something that inserts two lineshifts]
end tell
In general since you're dealing with a txt file, you do not need to "open" the file in an application and paste in text. We can read and write to text files directly from applescript. As such we read in the text from the template file, add whatever text we want to that, and then write the new text to a new file. If you then want to open and view the new file you can do that after. I did that in the "TextEdit" section of the code.
You can see at the end of the script I have subroutines to write a text file and also to change the file name to CAPS. So try the following...
-- initial variables
set templateFile to "Q:x:7:n7:GTD scripting:template folder:x.txt"
set copyFolder to "Q:X:7:SI:SIAG1:" -- notice this path ends in ":" because it's a folder
-- get the new name
display dialog "new_name_dialogue" default answer ""
set newName to (text returned of result)
set newPath to copyFolder & newName
-- get the text of the template file
set templateText to read file templateFile
-- add the file name in CAPS, a colon, and 2 returns at the beginning of templateText
set capsName to upperCase(newName)
set newText to capsName & ":" & return & return & templateText
-- write the newText to newPath
writeTo(newPath, newText, text, false)
-- open the new file in textedit
tell application "TextEdit" to open file newPath
(*============== SUBROUTINES ==============*)
on writeTo(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as text
if targetFile does not contain ":" then set targetFile to POSIX file targetFile as text
set openFile to open for access file targetFile with write permission
if apendData is false then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeTo
on upperCase(theText)
set chrIDs to id of theText
set a to {}
repeat with i from 1 to (count of chrIDs)
set chrID to item i of chrIDs
if chrID ≥ 97 and chrID ≤ 122 then set chrID to (chrID - 32)
set end of a to chrID
end repeat
return string id a
end upperCase
something that lets me open the file is needed here
tell application "TextEdit" to open Path_Of_X
something that pastes new_name in ALL CAPS
There is a really good third party scripting addition (Satimage OSAX) that you can use for things just like this (this will only work if you've downloaded the scripting addition)...
set UPPER_CASE to uppercase new_name & ":"
something that inserts two lineshifts
return & return