Applescript : I can't move duplicated file - applescript

I want to duplicate a file and move it to other folder and rename it.
But duplicated file was not moved to the folder and not renamed.
Here is my code.
"useskill" is folder.
set copyItem to duplicate i
set name of copyItem to "temp.png"
move copyItem to useskill
set name of copyItem to "0001.png"
I don't know where to I should fix because I'm new to Applescript.
I put all the code I wrote.
on adding folder items to this_folder after receiving added_items
tell application "Finder"
-- create folders if not exist
if not (exists folder "asleep" of this_folder) then
make new folder at this_folder with properties {name:"asleep"}
end if
set asleep to folder "asleep" of this_folder
if not (exists folder "attack" of this_folder) then
set attack to make new folder at this_folder with properties {name:"attack"}
make new folder at attack with properties {name:"north"}
make new folder at attack with properties {name:"northeast"}
make new folder at attack with properties {name:"east"}
make new folder at attack with properties {name:"southeast"}
make new folder at attack with properties {name:"south"}
make new folder at attack with properties {name:"southwest"}
make new folder at attack with properties {name:"west"}
make new folder at attack with properties {name:"northwest"}
end if
set attack to folder "attack" of this_folder
if not (exists folder "useskill" of this_folder) then
set useskill to make new folder at this_folder with properties {name:"useskill"}
end if
set useskill to folder "useskill" of this_folder
if not (exists folder "walk" of this_folder) then
set walk to make new folder at this_folder with properties {name:"walk"}
make new folder at walk with properties {name:"north"}
make new folder at walk with properties {name:"northeast"}
make new folder at walk with properties {name:"east"}
make new folder at walk with properties {name:"southeast"}
make new folder at walk with properties {name:"south"}
make new folder at walk with properties {name:"southwest"}
make new folder at walk with properties {name:"west"}
make new folder at walk with properties {name:"northwest"}
end if
set walk to folder "walk" of this_folder
-- add items
repeat with i in added_items
set itemName to name of i
--display dialog itemName
if itemName ends with ".png" then
if itemName starts with "asleep" then
--asleep
set name of i to "0001.png"
move i to asleep
else if itemName starts with "attack" then
--attack
set oldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set myList to text items of itemName
set frame to item 2 of myList as integer
set dirNum to item 3 of myList as integer
set dirStr to my dirStr(dirNum)
--display dialog dirStr
move i to folder dirStr of attack
set name of i to ("000" & frame & ".png")
set AppleScript's text item delimiters to oldDel
else if itemName starts with "walk" then
--walk
set oldDel to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set myList to text items of itemName
set frame to item 2 of myList as integer
set dirNum to item 3 of myList as integer
set dirStr to my dirStr(dirNum)
--display dialog dirStr
move i to folder dirStr of walk
set name of i to ("000" & frame & ".png")
if frame = 1 then
set copyItem to duplicate i
set name of copyItem to "temp.png"
move copyItem to useskill
if dirNum = 0 then
set name of copyItem to "0001.png"
set copyItem2 to duplicate copyItem to useskill
set name of copyItem2 to "0009.png"
else if dirNum = 40 then
set name of copyItem to "0002.png"
else if dirNum = 80 then
set name of copyItem to "0003.png"
else if dirNum = 130 then
set name of copyItem to "0004.png"
else if dirNum = 180 then
set name of copyItem to "0005.png"
else if dirNum = 230 then
set name of copyItem to "0006.png"
else if dirNum = 280 then
set name of copyItem to "0007.png"
else if dirNum = 320 then
set name of copyItem to "0008.png"
end if
else if frame = 2 then
set copyItem to duplicate i
set name of copyItem to "0006.png"
else if frame = 3 then
set copyItem to duplicate i
set name of copyItem to "0005.png"
end if
set AppleScript's text item delimiters to oldDel
end if
end if
end repeat
end tell
end adding folder items to
on dirStr(dirNum)
if dirNum is 0 then
return "south"
else if dirNum is 40 then
return "southeast"
else if dirNum is 80 then
return "east"
else if dirNum is 130 then
return "northeast"
else if dirNum is 180 then
return "north"
else if dirNum is 230 then
return "northwest"
else if dirNum is 280 then
return "west"
else if dirNum is 320 then
return "southwest"
end if
end dirStr
on retFileNameWithoutExt(fileNameStr)
set fLen to length of fileNameStr
set revText to (reverse of (characters of fileNameStr)) as string
set anOffset to offset of "." in revText
set fRes to text 1 thru (fLen - anOffset) of fileNameStr
return fRes
end retFileNameWithoutExt
Any help would be appreciated.
Thank you.
EDIT
#adayzdone Thank you for your answer.
But if itemName starts with "walk" and frame = 1, duplicated copyItem replace the existing file because they have same name "0001.png" when duplicated.
So I rewrited some of the code, but it did not work well.
--walk
set {frame, dirNum} to my parseName(itemName)
set dirStr to my dirStr(dirNum)
set name of anItem to ("000" & frame & ".png")
if frame = 1 then
(*set copyItem to duplicate anItem to ((this_folder as text) & "useskill") with replacing*)
set copyItem to duplicate anItem
set name of copyItem to "temp.png"
move copyItem to ((this_folder as text) & "useskill") with replacing
if dirNum = 0 then
set name of copyItem to "0001.png"
set copyItem2 to duplicate copyItem
set name of copyItem2 to "0009.png"
else if dirNum = 40 then ....
I intended to rename the item to"temp.png" and move it and rename it again.
But the item was not moved.
Is it impossible to move the item after rename?

You can try something along these lines...
on adding folder items to this_folder after receiving added_items
set this_folder_path to (quoted form of (POSIX path of this_folder))
do shell script "mkdir -p " & this_folder_path & "{'asleep','useskill'}; mkdir -p " & this_folder_path & "{'attack','walk'}/{'north','northeast','east','southeast','south','southwest','west','northwest'};"
repeat with anItem in added_items
tell application "Finder"
if anItem's name extension = "png" then
set itemName to name of anItem
if itemName starts with "asleep" then
set name of anItem to "0001.png"
move anItem to ((this_folder as text) & "asleep") with replacing
else if itemName starts with "attack" then
set {frame, dirNum} to my parseName(itemName)
set dirStr to my dirStr(dirNum)
set name of anItem to ("000" & frame & ".png")
move anItem to ((this_folder as text) & "attack:" & dirStr) with replacing
else if itemName starts with "walk" then
set {frame, dirNum} to my parseName(itemName)
set dirStr to my dirStr(dirNum)
set name of anItem to ("000" & frame & ".png")
if frame = 1 then
set copyItem to duplicate anItem to ((this_folder as text) & "useskill") with replacing
if dirNum = 0 then
set name of copyItem to "0001.png"
set copyItem2 to duplicate copyItem
set name of copyItem2 to "0009.png"
else if dirNum = 40 then
set name of copyItem to "0002.png"
else if dirNum = 80 then
set name of copyItem to "0003.png"
else if dirNum = 130 then
set name of copyItem to "0004.png"
else if dirNum = 180 then
set name of copyItem to "0005.png"
else if dirNum = 230 then
set name of copyItem to "0006.png"
else if dirNum = 280 then
set name of copyItem to "0007.png"
else if dirNum = 320 then
set name of copyItem to "0008.png"
end if
else if frame = 2 then
set copyItem to duplicate anItem
set name of copyItem to "0006.png"
else if frame = 3 then
set copyItem to duplicate anItem
set name of copyItem to "0005.png"
end if
move anItem to ((this_folder as text) & "walk:" & dirStr) with replacing
end if
end if
end tell
end repeat
end adding folder items to
on parseName(nameText)
set {TID, text item delimiters} to {text item delimiters, "."}
set f to text item 2 of nameText as integer
set d to text item 3 of nameText as integer
set text item delimiters to TID
return {f, d}
end parseName
on dirStr(dirNum)
if dirNum is 0 then
return "south"
else if dirNum is 40 then
return "southeast"
else if dirNum is 80 then
return "east"
else if dirNum is 130 then
return "northeast"
else if dirNum is 180 then
return "north"
else if dirNum is 230 then
return "northwest"
else if dirNum is 280 then
return "west"
else if dirNum is 320 then
return "southwest"
end if
end dirStr

Related

Applescript: if file contains any of names move to specific folder

I'm trying to make a script that will do this:
There will be a .txt file with a list of names, one per paragraph, like this:
name1
name2
name3
name4
name5
There also will be a folder with lots of files in it.
I want the script to look at every file in that folder, and in any of the names listed in .txt file are contained in the file name, then move that file to a specific folder. If the file name does not contain one of the names from the list, then move that file to a different folder.
Example:
- There are "name1", "name2" and "name3" in the .txt file.
- There are "000name2000.jpg", "000name7000.jpg" and "000name3000.jpg" in the folder.
- "000name2000.jpg" contains "name2" in it so it should be moved to folder1.
- "000name3000.jpg" should be moved to folder1 as well.
- And "000name7000.jpg" should be moved to folder2.
I want it to be so because this list with names will be very long and I want script to be as small as possible.
This is how my script looks like now:
property source_folder : alias "path:to:source_folder"
property tattoos_folder : alias "path:to:first_folder"
property models_folder : alias "path:to:second_folder"
property text_file : alias "path:to:text_file.txt"
process_folder(source_folder)
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
set container_name to name of (info for this_folder)
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
if folder of (info for this_item) is true then
process_folder(this_item)
else
process_item(this_item, container_name, i)
end if
end repeat
end process_folder
on process_item(this_item, c, i)
if i < 10 then
set i to "000" & i
else if (i < 100) and (i > 9) then
set i to "00" & i
else if (i < 1000) and (i > 99) then
set i to "0" & i
end if
set r to (random number from 0 to 9999)
if r < 10 then
set r to "000" & r
else if (r < 100) and (r > 9) then
set r to "00" & r
else if (r < 1000) and (r > 99) then
set r to "0" & r
end if
tell application "System Events"
-- get file extension so not overwritten
set e to name extension of this_item
set new_name to "" & r & "" & c & "" & i & "." & e
set name of this_item to new_name
move this_item to first_folder -- THIS IS WHERE THIS NEW PART OF CODE SHOULD BE
end if -- IF NAME IS (meets name from .txt file) THEN MOVE TO first_folder,
end tell -- IF ANOTHER THEN MOVE TO second_folder
end process_item
display notification "All images were processed." with title "New" sound name "Glass.aiff"
tell me to quit
This assumes you can define your text file and folder paths in the script. You can add choose dialogs if you need to.
This script puts all files in the source folder into a list, then it goes through each file, checking if a name in the name list matches, and if it does, moves it to folder1, otherwise, if it is still left after checking all the names, then moves it to folder2.
-- define folder/file locations
property nameFile : ((path to desktop) & "nameList.txt") as string
property sourceFolder : ((path to desktop) & "test:") as string
property folder1 : ((path to desktop) & "folder1:") as string
property folder2 : ((path to desktop) & "folder2:") as string
try
set move1List to {}
set move2List to {}
set nameList to paragraphs of (read file nameFile)
set fileList to list folder sourceFolder without invisibles
repeat with n from 1 to count (fileList)
set thisFile to item n of fileList
-- set fileName to name of (info for alias (sourceFolder & thisFile))
set fileRef to alias (sourceFolder & thisFile)
repeat with thisName in nameList
if (thisName as string) is in thisFile then
set end of move1List to fileRef
exit repeat
end if
end repeat
if exists fileRef then set end of move2List to fileRef
end repeat
display dialog "About to move: " & return & (count move1List) & " files to folder1" & return & (count move2List) & " files to folder2"
-- move all the files in the lists
tell application "Finder" -- can try "System Events"
move move1List to folder folder1
move move2List to folder folder2
end tell
-- could avoid Finder by iterating to a shell script using
-- do shell script "mv " & quoted form of thisFile & space & quoted form of folder1
on error err
display dialog err
end try

Selecting multiple files in Finder

In my applescript, I have a function which takes a selected file and writes its path into an xml file. If a folder is selected, i'm able to create a list with the files contained and send that to my function. However, if I select multiple finder items (via shift clicking), whether files or folders, I'm not able to send anything to the function.
here is the part where i get the files from the Finder
tell application "Finder"
set myPath to the selection
end tell
--if multiple files selected
if (count of myPath) is greater than 1 then
set fileList to every item of myPath
repeat with i in fileList
if (isDirectory(i)) then
else
myBigLoop(initialSuccess, i, watchFolder)
end if
end repeat
else if (isDirectory(myPath)) then
submitFolder(myPath, watchFolder)
else
set isFolder to false
set initialSuccess to true
myBigLoop(initialSuccess, myPath, watchFolder)
end if
on myBigLoop(initialSuccess, fileList, watchFolder)
repeat with myPath in fileList
if initialSuccess then
tell application "Finder"
set myFilename to myPath as alias
set myPath to the folder of myFilename
set myPath to myPath as string
set myFilename to name of myFilename
display dialog myFilename
end tell
end if --end InitialSuccess
end repeat
end myBigLoop
on isDirectory(someItem) -- someItem is a file reference
set filePosixPath to quoted form of (POSIX path of (someItem as alias))
set fileType to (do shell script "file -b " & filePosixPath)
if fileType ends with "directory" then return true
return false
end isDirectory
on submitFolder(myPath, watchFolder)
set isFolder to true
set initialSuccess to true
set fileList to item 1 of myPath
set fileList to get every file of fileList
set numFiles to count fileList
if numFiles is equal to 0 then
display dialog "There were no files in that folder."
return false
end if
myBigLoop(initialSuccess, fileList, watchFolder)
end submitFolder
I believe you should extend the Finder tell structure, because you're still working with files and folders later on:
tell application "Finder"
set myPath to the selection
--if multiple files selected
if (count of myPath) is greater than 1 then
set fileList to every item of myPath
repeat with i in fileList
if (isDirectory(i)) then
else
myBigLoop(initialSuccess, i, watchFolder)
end if
end repeat
else if (isDirectory(myPath)) then
submitFolder(myPath, watchFolder)
else
set isFolder to false
set initialSuccess to true
myBigLoop(initialSuccess, myPath, watchFolder)
end if
end tell

Applescript: Passing track metadata from text file to broadcast streaming app

I know virtually nothing about AppleScript and could do with some help.
While running, my broadcast playout system (MegaSeg) writes details of the track currently playing to a textfile called "NowPlaying" which contains solely the following contents, each on its own line and without square brackets:
Title: [title]
Artist: [artist]
Album: [album]
Time: [time in some format or other]
I want to pass this to my broadcast streamer LadioCast, which can be addressed via AppleScript, so that it sends info on what is playing to the streaming server.
MegaSeg doesn't support Applescript calls like 'tell application "MegaSeg"... set trackName to name of current track' so I can't do it that way. I have no idea about how to do this.
If we imagine that I was able to grab that info, this is what I would do with it:
set lastName to ""
set lastArtist to ""
set lastAlbum to ""
repeat
** insert missing file reading section here
** in the following, "title", "artist" and "album" are from the text file **
set trackName to title
set trackArtist to artist
set trackAlbum to album
** end of missing section
if trackName is not lastName and trackArtist is not lastArtist and trackAlbum is not lastAlbum then
set lastName to trackName
set lastArtist to trackArtist
set lastAlbum to trackAlbum
tell application "LadioCast"
set metadata song to trackName & " – " & trackArtist & " – " & trackAlbum
end tell
end if
delay 15
end repeat
Thanks in advance.
--Richard E
===
I tried the suggestions from #DigiMonk and they were very helpful, but not all of them worked. First, the file is in a specific location and not on the desktop; second, I could not get 'trim_line' to work at all - I got "script does not understand trim_line message". However the text in the file seems to be already trimmed.
The script below nearly works; when run from the Applescript Editor it does seem to get the Title, Artist and Album into the variables. However when I try running it from LadioCast I get an EOF -39 error. More importantly, as soon as I run this, MegaSeg stops updating the file, forever. I am presumably locking the file to read from it and stopping MegaSeg writing to it. How do I avoid this?
set lastName to ""
set lastArtist to ""
set lastAlbum to ""
set lastTime to ""
set trackName to ""
set trackArtist to ""
set trackAlbum to ""
set sourcePath to ""
repeat
set sourcePath to open for access file "Library:MegaSeg User Data:Logs:Logs for MegaSeg System (4):NowPlaying"
set thisText to read sourcePath as text
close access file "Library:MegaSeg User Data:Logs:Logs for MegaSeg System (4):NowPlaying"
set the paragraphList to every paragraph of thisText
repeat with i from 1 to number of items in paragraphList
set thisItem to item i of paragraphList
if thisItem starts with "Title:" then
set x to the offset of "Title:" in thisItem
set trackName to (text (x + 6) thru -1 of thisItem)
else if thisItem starts with "Artist:" then
set x to the offset of "Artist:" in thisItem
set trackArtist to (text (x + 7) thru -1 of thisItem)
else if thisItem starts with "Album:" then
set x to the offset of "Album:" in thisItem
set trackAlbum to (text (x + 6) thru -1 of thisItem)
end if
end repeat
if trackName is not lastName and trackArtist is not lastArtist and trackAlbum is not lastAlbum then
set lastName to trackName
set lastArtist to trackArtist
set lastAlbum to trackAlbum
tell application "LadioCast"
set metadata song to trackName & " – " & trackArtist & " – " & trackAlbum
end tell
end if
delay 15
end repeat
May be this helps: (feed sourcePath with the path to your NowPlaying.txt file)
set sourcePath to (path to desktop) & "NowPlaying.txt" as text
set thisText to my readFile(sourcePath)
set the paragraphList to every paragraph of thisText
set lastName to ""
set lastArtist to ""
set lastAlbum to ""
set lastTime to ""
repeat with i from 1 to number of items in paragraphList
set thisItem to item i of paragraphList
--log thisItem
if thisItem starts with "Title:" then
set x to the offset of "Title:" in thisItem
set y to (text (x + 6) thru -1 of thisItem)
set lastName to my trim_line(y, " ", 2)
else if thisItem starts with "Artist:" then
set x to the offset of "Artist:" in thisItem
set y to (text (x + 7) thru -1 of thisItem)
set lastArtist to my trim_line(y, " ", 2)
else if thisItem starts with "Album:" then
set x to the offset of "Album:" in thisItem
set y to (text (x + 6) thru -1 of thisItem)
set lastAlbum to my trim_line(y, " ", 2)
else if thisItem starts with "Time:" then
set x to the offset of "Time:" in thisItem
set y to (text (x + 5) thru -1 of thisItem)
set lastTime to my trim_line(y, " ", 2)
end if
end repeat
log "lastName = '" & lastName & "'"
log "lastArtist = '" & lastArtist & "'"
log "lastAlbum = '" & lastAlbum & "'"
on readFile(thisFile)
set thisFile to thisFile as text
if thisFile is "" then return ""
try
set fi to open for access file the thisFile
set myData to read fi as text
close access file the thisFile
return myData
on error
try
close access file the thisFile
return ""
end try
end try
end readFile
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line

Applescript indesign to list all color swatches from multiple files

I am working on finishing up an script droplet to pull all used swatches out of multiple indesign documents that I drop on the script and list them. I am adapting this from a script I wrote to put all used swatches from a single file.
I have the basics down but have run into two problems and cant find an answer.
Problem 1: I need to add the line to "repeat until swatchCount < 2" but this would ad a repeat inside a repeat. Doesn't work.
Problem 2: (the biggest problem) The "colorList" needs to add the colors from each of the documents together into a single list. Since I have it on repeat it is only listing the colors from the last processed file. How do I have the list save each files color and then list them all?
I would appreciate any help I have hit a wall.
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
set this_item to POSIX path of this_item
tell application "Adobe InDesign CC"
open this_item
tell active document
delete unused swatches
set allSwatches to every swatch
end tell
set swatchCount to count of allSwatches
set colorList to ""
-- repeat until swatchCount < 2
set thisSwatch to item swatchCount of allSwatches
try
set swatchProps to type of thisSwatch
set swatchProps to "Gradient"
on error
set swatchProps to "Color"
end try
if swatchProps = "Color" then
set swatchName to name of thisSwatch as string
set swatchType to model of thisSwatch as string
set swatchSpace to space of thisSwatch as string
set swatchColor to color value of thisSwatch
if swatchType contains "spot" then
set swatchType to "Spot"
else
if swatchType contains "prss" then
set swatchType to "Process"
end if
end if
if swatchSpace contains "RGB" then
set rrr to ((item 1 of swatchColor) as integer)
set ggg to ((item 2 of swatchColor) as integer)
set bbb to ((item 3 of swatchColor) as integer)
set swatchMix to (" value: R-" & rrr & " G-" & ggg & " B-" & bbb) as string
if swatchName does not contain "registration" then
set swatchItem to "Name: " & swatchName & swatchMix & " space: RGB" & " type: " & swatchType & return
else
set swatchItem to ""
end if
else
if swatchSpace contains "CMYK" then
set ccc to ((item 1 of swatchColor) as integer)
set mmm to ((item 2 of swatchColor) as integer)
set yyy to ((item 3 of swatchColor) as integer)
set kkk to ((item 4 of swatchColor) as integer)
set swatchMix to (" value: C-" & ccc & " M-" & mmm & " Y-" & yyy & " K-" & kkk) as string
if swatchName does not contain "registration" then
set swatchItem to "Name: " & swatchName & swatchMix & " space:CMYK" & " type: " & swatchType & return
else
set swatchItem to ""
end if
else
if swatchSpace contains "LAB" then
set lll to ((item 1 of swatchColor) as integer)
set aaa to ((item 2 of swatchColor) as integer)
set bbb to ((item 3 of swatchColor) as integer)
set swatchMix to (" value: L-" & lll & " A-" & aaa & " B-" & bbb) as string
if swatchName does not contain "registration" then
set swatchItem to "Name: " & swatchName & swatchMix & " space: LAB" & " type: " & swatchType & return
else
set swatchItem to ""
end if
end if
end if
end if
set colorList to colorList & swatchItem
end if
tell active document to close saving no
set swatchCount to swatchCount - 1
--end repeat
end tell
end repeat
set dragged_items to these_items as string
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theClientName to text item 2 of dragged_items
set theFileName to text item 5 of dragged_items
set AppleScript's text item delimiters to old_delimiters
set theOrderNumber to text 1 through 5 of theFileName
set headerInfo to "Client: " & theClientName & " Order # " & theOrderNumber & " File: " & theFileName
tell application "Adobe InDesign CC"
tell view preferences
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
make new document with properties {document preferences:{page width:8.5, page height:11}}
tell view preferences
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
tell active document
set zero point to {0, 0}
set properties of guide preferences to {guides shown:false}
set properties of text preferences to {show invisibles:false}
set properties of view preferences to {ruler origin:page origin, horizontal measurement units:inches, show frame edges:false, show rulers:true, vertical measurement units:inches}
tell layout window 1
zoom given fit page
set properties to {view display setting:typical, transform reference point:top left anchor}
end tell
make new text frame with properties {geometric bounds:{0.5, 0.5, 0.75, 8.0}, contents:headerInfo, color:"None"}
set paragraphCount to count of paragraphs of colorList
repeat until paragraphCount > 19
set colorList to colorList & "name: _________________________" & " value: ____________________" & " space: ______" & " type: _________" & return
set paragraphCount to count of paragraphs of colorList
end repeat
make new text frame with properties {geometric bounds:{4.5, 0.5, 20.0, 8.0}, contents:colorList, color:"None"}
tell text frame 1
tell every text to set point size to 10
tell every paragraph
make tab stop with properties {alignment:left align, position:2.875}
make tab stop with properties {alignment:left align, position:5.125}
make tab stop with properties {alignment:left align, position:6.375}
end tell
set geometric bounds to {1.0, 0.5, 11, 8.0}
end tell
end tell
end tell
end open
on run
-- Handle the case where the script is launched without any dropped files
open (choose file with multiple selections allowed)
end run
I have added the changes that you suggested "Darrick Herwehe" but am getting an error now on a different part.
Can’t get name of color id 344 of document id 30
--name of color id 344 of document id 29 of application "Adobe InDesign CC"--
getting this in reference to: set swatchName to name of thisSwatch
on open these_items
set colorList to ""
set swatchItem to ""
repeat with i from 1 to the count of these_items
--Get swatches from document start
set this_item to item i of these_items
set the item_info to info for this_item
set this_item to POSIX path of this_item
tell application "Adobe InDesign CC"
open this_item
tell active document
delete unused swatches
set allSwatches to every swatch
end tell
set swatchCount to count of allSwatches
repeat until swatchCount < 2
repeat with j from 1 to (count allSwatches)
set thisSwatch to item swatchCount of allSwatches
try
set swatchProps to type of thisSwatch
set swatchProps to "Gradient"
on error
set swatchProps to "Color"
end try
if swatchProps = "Color" then
set swatchName to name of thisSwatch
set swatchType to model of thisSwatch
set swatchSpace to space of thisSwatch
set swatchColor to color value of thisSwatch
if swatchType contains "spot" then
set swatchType to "Spot"
else
if swatchType contains "prss" then
set swatchType to "Process"
end if
end if
if swatchSpace contains "RGB" then
set rrr to ((item 1 of swatchColor) as integer)
set ggg to ((item 2 of swatchColor) as integer)
set bbb to ((item 3 of swatchColor) as integer)
set swatchMix to (" value: R-" & rrr & " G-" & ggg & " B-" & bbb) as string
if swatchName does not contain "registration" then
set swatchItem to "Name: " & swatchName & swatchMix & " space: RGB" & " type: " & swatchType & return
else
set swatchItem to ""
end if
else
if swatchSpace contains "CMYK" then
set ccc to ((item 1 of swatchColor) as integer)
set mmm to ((item 2 of swatchColor) as integer)
set yyy to ((item 3 of swatchColor) as integer)
set kkk to ((item 4 of swatchColor) as integer)
set swatchMix to (" value: C-" & ccc & " M-" & mmm & " Y-" & yyy & " K-" & kkk) as string
if swatchName does not contain "registration" then
set swatchItem to "Name: " & swatchName & swatchMix & " space:CMYK" & " type: " & swatchType & return
else
set swatchItem to ""
end if
else
if swatchSpace contains "LAB" then
set lll to ((item 1 of swatchColor) as integer)
set aaa to ((item 2 of swatchColor) as integer)
set bbb to ((item 3 of swatchColor) as integer)
set swatchMix to (" value: L-" & lll & " A-" & aaa & " B-" & bbb) as string
if swatchName does not contain "registration" then
set swatchItem to "Name: " & swatchName & swatchMix & " space: LAB" & " type: " & swatchType & return
else
set swatchItem to ""
end if
end if
end if
end if
tell active document to close saving no
set colorList to colorList & swatchItem
end if
set swatchCount to swatchCount - 1
end repeat
end repeat
end tell
end repeat
set dragged_items to these_items as string
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theClientName to text item 2 of dragged_items
set theFileName to text item 5 of dragged_items
set AppleScript's text item delimiters to old_delimiters
set theOrderNumber to text 1 through 5 of theFileName
set headerInfo to "Client: " & theClientName & " Order # " & theOrderNumber & " File: " & theFileName
tell application "Adobe InDesign CC"
tell view preferences
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
make new document with properties {document preferences:{page width:8.5, page height:11}}
tell view preferences
set horizontal measurement units to inches
set vertical measurement units to inches
end tell
tell active document
set zero point to {0, 0}
set properties of guide preferences to {guides shown:false}
set properties of text preferences to {show invisibles:false}
set properties of view preferences to {ruler origin:page origin, horizontal measurement units:inches, show frame edges:false, show rulers:true, vertical measurement units:inches}
tell layout window 1
zoom given fit page
set properties to {view display setting:typical, transform reference point:top left anchor}
end tell
make new text frame with properties {geometric bounds:{0.5, 0.5, 0.75, 8.0}, contents:headerInfo, color:"None"}
set paragraphCount to count of paragraphs of colorList
repeat until paragraphCount > 19
set colorList to colorList & "name: _________________________" & " value: ____________________" & " space: ______" & " type: _________" & return
set paragraphCount to count of paragraphs of colorList
end repeat
make new text frame with properties {geometric bounds:{4.5, 0.5, 20.0, 8.0}, contents:colorList, color:"None"}
tell text frame 1
tell every text to set point size to 10
tell every paragraph
make tab stop with properties {alignment:left align, position:2.875}
make tab stop with properties {alignment:left align, position:5.125}
make tab stop with properties {alignment:left align, position:6.375}
end tell
set geometric bounds to {1.0, 0.5, 11, 8.0}
end tell
end tell
end tell
end open
on run
-- Handle the case where the script is launched without any dropped files
open (choose file with multiple selections allowed)
end run
If you have any insight I would much appriciate it.
Thanks again
Matt
You can nest repeat loops. It's not a problem, it's done all the time. You just have to define a different iteration variable from your first repeat loop. In your case, I would use j.
As for getting all of the colors into one list, you neeed to define colorList outside your first repeat loop. That way it doesn't get overwritten during each iteration.
An outline for that would be:
on open these_items
set colorList to ""
repeat with i from 1 to the count of these_items
-- [ Get swatches from the document ]
repeat with j from 1 to (count allSwatches)
-- [ Process your swatches ]
set colorList to colorList & swatchItem
end repeat
end repeat
end open

Folder image to iTunes artwork in applescript : not working anymore

Anyone of you guys could point me to why this applescript (which was working on snow leopard) does not work anymore on 10.7 Lion.
It intend to copy the file named "folder.jpg" from each album folder into ID3 tags of selected mp3 in iTunes.
property tempfile : ((path to temporary items as string) & "itunespicturefile_temporaire.pict")
global vPictFolder
tell application "iTunes"
set v_TrackSelection to selection
if v_TrackSelection is not {} then
repeat with vTrack in v_TrackSelection
set vPictFolder to my (ParentFromPath(location of vTrack as string)) as text
set thisPict to my getpictData("folder.jpg")
if thisPict is not "" then
delete artworks of vTrack
set data of artwork 1 of vTrack to (thisPict)
end if
end repeat
else
display dialog ("select tracks first !")
end if
end tell
on getpictData(vAlbumpictName)
tell application "Finder" to tell file vAlbumpictName of folder vPictFolder to if exists then
set t_file to it as string
else
display dialog vPictFolder & vAlbumpictName
return ""
end if
do shell script "/opt/local/bin/convert " & quoted form of POSIX path of t_file & " " & quoted form of POSIX path of tempfile
display dialog "ok"
return read (tempfile as alias) from 513 as picture
end getpictData
on ParentFromPath(thePath)
set wantPath to true
set thePath to (thePath as text)
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set pathAsList to text items of thePath
if the last character of thePath is ":" then
set idx to (the number of text items in thePath) - 2
else
set idx to -2
end if
if wantPath then
set folderName to ((text items 1 through idx of pathAsList) as text) & ":"
else
set folderName to item idx of pathAsList
end if
set AppleScript's text item delimiters to saveDelim
return folderName
end ParentFromPath
Because Picture format (".pict") is not supported on Lion and newer OS.
You can use the term picture to read a image file (JPEG, PNG, ...), the format will not be in the Picture format , but the original format of the file.
tell application "iTunes"
set v_TrackSelection to selection
if v_TrackSelection is not {} then
repeat with vTrack in v_TrackSelection
set vPictFolder to my (ParentFromPath(location of vTrack as string)) as text
set thisPict to my getpictData(vPictFolder & "folder.jpg")
if thisPict is not "" then
delete artworks of vTrack
set data of artwork 1 of vTrack to (thisPict)
end if
end repeat
else
display dialog ("select tracks first !")
end if
end tell
on getpictData(tFile)
try
return (read (tFile as alias) as picture)
end try
display dialog tFile
return "" -- not exists
end getpictData

Resources