Hi all!
I have some code that I’m working on, where a user inputs three text fields, the first two are folders, the third is a file name. The program then checks to see if the first folder exists, if not it makes the folder, then it checks to see if the second folder exists, and makes it. (This second folder is inside the first one) and then the program moves the given file to the new location changing it’s name.
So far my code seems to be working well, with one exception. The second input (that is the second folder) will only work if it’s an integer. If I put text in the second text box, I get an error saying it can’t convert “text” to type integer. I can’t for the life of me figure out what it’s trying to do, or where it’s trying to do it. Anyone have any ideas?
Here is the subroutine, activated via a button click.
(I’ve set up some beeps into the program, and when I run it, I only get two beeps back. But I don’t understand why it would want an integer at that point of the program…)
set theImage to (item currentListPosition of sourceList) as string
--check move file conditions
--check rename conditions
--move and rename file appropriately
--change list entry to reflect new path
--load next photo
tell progress indicator "theSpinner" of window "mainWindow" to start
if fileMoveState is 1 and fileRenameState is 1 then
set theNewFolder to contents of text field "theFolderBox" of window "mainWindow"
set theNewName to contents of text field "theImageNameBox" of window "mainWindow"
tell application "Finder"
if not (exists folder theNewFolder of theDestinationFolder) then
set newDirectory to theDestinationFolder & theNewFolder as string
do shell script "mkdir " & (quoted form of POSIX path of (newDirectory))
my updateDestList(theDestinationFolder, 1)
else
set newDirectory to theDestinationFolder & theNewFolder as string
end if
end tell
if subFolderStatus is 0 then
beep
set theSubFolder to contents of text field "theSubFolderBox" of window "mainWindow" as string
if theNewName is "" then
set theNewName to theSubFolder
end if
if theSubFolder is not "" then
tell application "Finder"
beep
if not (exists folder theSubFolder of newDirectory) then
beep
set newSubDirectory to newDirectory & ":" & theSubFolder as string
do shell script "mkdir " & (quoted form of POSIX path of (newSubDirectory))
my updateDestList(newDirectory, 2)
set newDirectory to newSubDirectory
else
set newDirectory to newDirectory & theSubFolder as string
end if
end tell
end if
end if
if theNewName is "" then
set theNewName to theNewFolder
end if
tell application "Finder"
set finalList to list folder newDirectory without invisibles
set finalCount to the number of items of finalList
end tell
set thePath to newDirectory & ":" & theNewName & " " & finalCount & ".jpg" as string
do shell script "mv " & (quoted form of POSIX path of (theImage as string)) & " " & (quoted form of POSIX path of thePath)
Thanks much!