Can anyone help me condense this script?
Maybe there is a better solution entirely, but this does work.
What I am doing is copying a selected file that doesn’t have an extension. (We often get PC files that the mac doesn’t recognize.)
This script copies the file 8 times and adds different extensions. Then Photoshop tries to open all. It would be nice if it stopped on the first file it opens.
As you can see the script is cumbersome. I am still going to do so cleanup in the mean time. But some tidbits of help would be very nice.
-Jeff
on open files_
try
tell application "Finder"
try
set testFileFolder to folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
set filesToDelete to every file of folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
repeat with i from 1 to (count of items of filesToDelete)
set the_path_to_delete_1 to (item i of filesToDelete) as string
if (the_path_to_delete_1 as string) ends with "" then
do shell script "rm " & quoted form of POSIX path of the_path_to_delete_1
end if
end repeat
update (files of entire contents of testFileFolder)
end try
try
set destPath to folder ((startup disk as Unicode text) & "Applications:Utilities:")
set foldName to make new folder at destPath with properties {name:"testFileFolder"}
set thePath to destPath & foldName
on error
try
set thePath to folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
end try
try
delete entire contents of thePath
end try
end try
duplicate files_ to folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
delay 3
set selFileName to (name of every file of testFileFolder)
end tell
on error errMsg
display dialog errMsg
end try
tell application "Finder"
set thePathNew to folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
set selFileFile to (every file of thePathNew)
end tell
set myFile to 8
tell application "Finder"
repeat myFile times
duplicate selFileFile
end repeat
end tell
--delay 8
tell application "Finder"
set theFldr to folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
end tell
tell application "Finder"
----
------
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .jpg extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".jpg" as string
end repeat
tell application "Finder"
update files of folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
end tell
----
----
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .gif extension to copy .
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".gif" as string
end repeat
------
------
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .tif extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy 1"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".tif" as string
end repeat
----
-----
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .png extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy 2"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".png" as string
end repeat
----
----
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .pdf extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy 3"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".pdf" as string
end repeat
----
-----
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .ai extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy 4"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".ai" as string
end repeat
----
-----
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .eps extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy 5"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".eps" as string
end repeat
----
-----
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .psd extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy 6"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".psd" as string
end repeat
----
-----
try -- because alias list won't work if there is only one file.
set theFiles to (file 1 of theFldr) as alias list
on error
set theFiles to (file 1 of theFldr) as alias as list
end try
repeat with aFile in theFiles -- this loop simply adds a .bmp extension to copy.
set theName to name of aFile
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to " copy 7"
set newParts to (text items of theName)
set AppleScript's text item delimiters to TID
set the name of aFile to newParts & ".bmp" as string
end repeat
end tell
---
----
tell application "Finder"
set allFiles to folder ((startup disk as Unicode text) & "Applications:Utilities:testFileFolder")
end tell
tell application "Adobe Photoshop CS"
activate
repeat with i from 1 to number of items in allFiles
set this_item to item i of allFiles as string
try
open file this_item
end try
end repeat
end tell
end open