Applescript date property in Reminders.app - applescript

I made this code that its supposed to parse a given string separated by "/" with the message, day and time, then make a Reminder in Mountain Lion Reminders.app.
My problems comes when Reminders doesn't seem to like the date I'm passing to it for no good reason.
I get this error message:
Invalid date and time date August 6 2012 6:00pm of list Reminders.
Here's my code:
--explode © 2008 ljr (http://applescript.bratis-lover.net)
on explode(delimiter, input)
local delimiter, input, ASTID
set ASTID to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to delimiter
set input to text items of input
set AppleScript's text item delimiters to ASTID
return input --> list on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't explode: " & eMsg number eNum
end try
end explode
--reminders © 2012 Jonathan Wiesel (http://github.com/jonathanwiesel)
set myList to explode("/", "visit my mom/today/6:00pm")
set theReminder to item 1 of myList
set queryDay to item 2 of myList
set theHour to item 3 of myList
set theYear to year of (current date)
if queryDay = "today" then
set theDay to day of (current date) as string
set theMonth to month of (current date)
set theDate to theMonth & " " & theDay & " " & theYear
else if queryDay = "tomorrow" then
set theDay to (day of ((current date) + (24 * 60 * 60)))
if (day of (current date)) < (day of ((current date) + (24 * 60 * 60)))
set theMonth to month of (current date)
else
set theMonth to (month of ((current date) + (30 * 24 * 60 * 60)))
end if
if year of (current date) < year of ((current date) + (24 * 60 * 60)) then
set theYear to (year of (current date)) + 1
set theDate to theMonth & " " & theDay & " " & theYear & " "
else
set theYear to year of (current date)
set theDate to theMonth & " " & theDay & " " & theYear & " "
end if
else
set theDate to queryDay
end if
set stringedDate to theDate as string
set stringedHour to theHour as string
set stringedAll to stringedDate & " " & stringedHour
tell application "Reminders"
tell list "Reminders"
make new reminder with properties {name:theReminder, due date:date stringedAll}
end tell
end tell

Well there is a good reason. You are telling the Reminders application to convert the date in string format to a date object. Reminders does not know how to do that. Applescript does. So just change your last few lines of your script to make applescript do it as follows. Basically you should never tell an application to do something that is not in its applescript dictionary.
set stringedAll to date (stringedDate & " " & stringedHour)
tell application "Reminders"
tell list "Reminders"
make new reminder with properties {name:theReminder, due date:stringedAll}
end tell
end tell

Related

Renaming PDF File with Apple Script

I'm trying to rename a finder item called "Invoice Template.pdf" when it is added to my folder with Automator. However, every time the script runs, I get Finder got an error: Can’t set file "Invoice Template.pdf" to "Invoice 11.08.2021.pdf". Any ideas why?
tell application "Finder"
set dateObj to (current date)
set theMonth to text -1 thru -2 of ("0" & (month of dateObj as number))
set theDay to text -1 thru -2 of ("0" & day of dateObj)
set theYear to year of dateObj
set dateStamp to "" & theMonth & "." & theDay & "." & theYear
set theFile to "DBF Invoice Template.pdf"
set theName to "Invoice"
set the name of file theFile to theName & " " & dateStamp & ".pdf"
end tell
set dateObj to (current date)
set theMonth to text -1 thru -2 of ("0" & (month of dateObj as number))
set theDay to text -1 thru -2 of ("0" & day of dateObj)
set theYear to year of dateObj
set dateStamp to "" & theMonth & "." & theDay & "." & theYear
set theFileHFS to (choose file of type "com.adobe.pdf") as text
set theName to "Invoice"
tell application "Finder"
set the name of file theFileHFS to theName & " " & dateStamp & ".pdf"
end tell
You need to tell Finder where the file is:
property myFolder: "/Users/MYUSERNAME/Dropbox/Invoices" as POSIX file
tell application "Finder"
...
set theFile to "DBF Invoice Template.pdf"
set theName to "Invoice"
set the name of file theFile of folder myFolder to theName & " " & dateStamp & ".pdf"
end tell

Set creation date using SetFile / date formatting

I'd like to copy creation date from a file and apply it to the folder the file is sitting in. I'm using SetFile for this purpose. I"m getting error: Invalid date/time. My assumption is that it's the format of the date that is not working. How do I format the date properly? Could someone suggest solution? Thanks
set filesToProcess to choose folder with prompt "Select folders:" with multiple selections allowed
repeat with thisFile in filesToProcess
tell application "Finder"
try
set creationDate to creation date of (first file in the entire contents of thisFile whose name ends with "low_r.pdf")
set formattedCreationDate to --creationDate needs reformatting?
do shell script "SetFile -d " & formattedCreationDate & " " & quoted form of (POSIX path of thisFile)
on error fileNotFound
set label index of thisFile to 2
display dialog fileNotFound
end try
end tell
end repeat
Final working code:
set filesToProcess to choose folder with prompt "Select folders:" with multiple selections allowed
repeat with thisFile in filesToProcess
tell application "Finder"
try
set creationDate to creation date of (first file in the entire contents of thisFile whose name ends with "low_r.pdf")
set formattedCreationDate to quoted form of my stringForDate(creationDate)
set formattedFolderLocation to quoted form of (POSIX path of thisFile)
do shell script "SetFile -d " & formattedCreationDate & " " & formattedFolderLocation
on error errorMsg
set label index of thisFile to 2
--display dialog errorMsg
end try
end tell
end repeat
on stringForDate(aDate)
if aDate is "" then return null
if class of aDate is not date then return null
set {year:dYear, month:dMonth, day:dDay, hours:dHours, minutes:dMinutes, seconds:dSeconds} to aDate
set dMonth to dMonth as integer
if dMonth < 10 then set dMonth to "0" & dMonth
if dDay < 10 then set dDay to "0" & dDay
return ((dMonth & "/" & dDay & "/" & dYear & " " & dHours & ":" & dMinutes & ":" & dSeconds) as string)
end stringForDate
Thanks to everyone for contributions and #Zero for sharing the subroutine
Try this.
set filesToProcess to choose folder with prompt "Select folders:" with multiple selections allowed
repeat with thisFile in filesToProcess
tell application "Finder"
try
set theFileDate to (creation date of (first file in folder thisFile whose name ends with "low_r.pdf"))
set formattedCreationDate to (word 2 of short date string of theFileDate & "/" & word 1 of short date string of theFileDate & "/" & word 3 of short date string of theFileDate) & space & time string of theFileDate
--need to flip dd/mm/yyyy to be mm/dd/yyyy Ues this line -->>set formattedCreationDate to short date string of theFileDate & space & time string of theFileDate <<-- instead if your country's date format is already mm/dd/yyyy
my doCommand(formattedCreationDate, thisFile)
on error fileNotFound
set label index of thisFile to 2
display dialog fileNotFound
end try
end tell
end repeat
on doCommand(formattedCreationDate, thisFile)
do shell script "SetFile -d " & (quoted form of formattedCreationDate) & " " & quoted form of (POSIX path of thisFile)
end doCommand

"Expected “,” but found property error using Apple Script

I using Apple script to get the required details from Microsoft outlook. Its totally working fine on the Mountian Lion OsX(10.8.3) but when i use the same script its failing and throwing me the error ""Expected “,” but found property".
Below is the Apple Script which i am using.
on encodeXML(s)
set AppleScript's text item delimiters to "&"
set components to every text item of s
set AppleScript's text item delimiters to "&"
set s to components as string
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to "<"
set components to every text item of s
set AppleScript's text item delimiters to "<"
set s to components as string
set AppleScript's text item delimiters to ">"
set components to every text item of s
set AppleScript's text item delimiters to ">"
set s to components as string
set AppleScript's text item delimiters to "\""
set components to every text item of s
set AppleScript's text item delimiters to """
set s to components as string
set AppleScript's text item delimiters to "'"
set components to every text item of s
set AppleScript's text item delimiters to "&apos;"
set s to components as string
set AppleScript's text item delimiters to ""
return s
end encodeXML
on meetingNumber(s)
set AppleScript's text item delimiters to "Meeting Number:"
set components to every text item of s
if (count of components) is less than 2 then
return ""
end if
set s to second text item of components
set AppleScript's text item delimiters to "To join"
set components to every text item of s
set s to first text item of components
set AppleScript's text item delimiters to "<"
set components to every text item of s
set s to first text item of components
set AppleScript's text item delimiters to "&"
set components to every text item of s
set s to first text item of components
set AppleScript's text item delimiters to "----"
set components to every text item of s
set s to first text item of components
set AppleScript's text item delimiters to " "
set components to every text item of s
set AppleScript's text item delimiters to ""
return components as string
end meetingNumber
on trimContents(s)
set AppleScript's text item delimiters to "Meeting Number:"
set components to every text item of s
if (count of components) is less than 2 then
return ""
end if
set s to second text item of components
set AppleScript's text item delimiters to "To join"
set components to every text item of s
set s to first text item of components
set AppleScript's text item delimiters to "<"
set components to every text item of s
set s to first text item of components
set AppleScript's text item delimiters to "&"
set components to every text item of s
set s to first text item of components
set AppleScript's text item delimiters to "----"
set components to every text item of s
set AppleScript's text item delimiters to ""
return "Meeting Number: " & first text item of components
end trimContents
on getEventKeys(theEvent)
set r to ""
tell application "Microsoft Outlook"
set r to r & " <wxp:meeting>
"
set r to (r & " <wxp:appID>" & id of theEvent as string) & "</wxp:appID>
"
set t to (content of theEvent as string)
set t to my trimContents(t)
set r to (r & " <wxp:content>" & my encodeXML(t)) & "</wxp:content>
"
set r to r & " </wxp:meeting>
"
end tell
return r
end getEventKeys
on getEvent(theEvent)
set retVal to ""
tell application "Microsoft Outlook"
set retVal to retVal & "<wxp:meeting>"
set retVal to (retVal & "<wxp:subject>" & my encodeXML(subject of theEvent as string)) & "</wxp:subject>"
set retVal to (retVal & "<wxp:organizer>" & organizer of theEvent as string) & "</wxp:organizer>"
set retVal to (retVal & "<wxp:startDate>" & start time of theEvent as string) & "</wxp:startDate>"
set retVal to (retVal & "<wxp:endDate>" & end time of theEvent as string) & "</wxp:endDate>"
set retVal to (retVal & "<wxp:appID>" & ID of theEvent as string) & "</wxp:appID> "
set outType to ""
if (is recurring of theEvent) then
set recur to recurrence of theEvent
set recurType to recurrence type of recur as string
if recurType is "daily" then
set outType to "DAILY"
else if recurType is "weekly" then
set outType to "WEEKLY"
else if recurType is "absolute monthly" or recurType is "relative monthly" then
set outType to "MONTHLY"
else if recurType is "absolute yearly" or recurType is "relative yearly" then
set outType to "YEARLY"
end if
set retVal to retVal & "<wxp:repeatType>" & outType & "</wxp:repeatType>
"
set retVal to retVal & "<wxp:interval>" & occurrence interval of recur & "</wxp:interval>
"
if end type of end date of recur as string is "end numbered type" then
set retVal to retVal & "<wxp:afterMeetingNumber>" & data of end date of recur & "</wxp:afterMeetingNumber>
"
else if end type of end date of recur as string is "end date type" then
set retVal to (retVal & "<wxp:expirationDate>" & data of end date of recur as string) & "</wxp:expirationDate>
"
end if
if recurType is "relative monthly" then
set retVal to retVal & "<wxp:weekInMonth>" & ordinal of recur & "</wxp:weekInMonth>"
end if
if recurType is "weekly" or recurType is "relative monthly" then
set bitmap to 0
if sunday of days of week of recur then
set bitmap to bitmap + 1
end if
if monday of days of week of recur then
set bitmap to bitmap + 2
end if
if tuesday of days of week of recur then
set bitmap to bitmap + 4
end if
if wednesday of days of week of recur then
set bitmap to bitmap + 8
end if
if thursday of days of week of recur then
set bitmap to bitmap + 16
end if
if friday of days of week of recur then
set bitmap to bitmap + 32
end if
if saturday of days of week of recur then
set bitmap to bitmap + 64
end if
set retVal to retVal & "<wxp:dayInWeek>" & bitmap & "</wxp:dayInWeek>
"
end if
else
set retVal to retVal & "<wxp:repeatType></wxp:repeatType>
"
end if
if (has reminder of theEvent) then
set retVal to (retVal & " <wxp:reminder>" & reminder time of theEvent as string) & "</wxp:reminder>
"
end if
--set attendees to attendee of theEvent
set retVal to retVal & " <wxp:attendees>
"
repeat with theAttendee in required attendee of theEvent
set retVal to retVal & my writeAttendee(theAttendee, "REQUIRED")
end repeat
repeat with theAttendee in optional attendee of theEvent
set retVal to retVal & my writeAttendee(theAttendee, "OPTIONAL")
end repeat
repeat with theAttendee in resource attendee of theEvent
set retVal to retVal & my writeAttendee(theAttendee, "RESOURCE")
end repeat
set retVal to retVal & " </wxp:attendees>
"
set retVal to (retVal & " <wxp:content>" & my encodeXML(content of theEvent as string)) & "</wxp:content>
"
set retVal to retVal & " </wxp:meeting>
"
end tell
return retVal
end getEvent
on writeAttendee(theAttendee, theType)
tell application "Microsoft Outlook"
set retVal to ""
if (status of theAttendee as string) is not "declined" then
set em to email address of theAttendee
set retVal to retVal & " <wxp:attendee>
"
try
set retVal to (retVal & " <wxp:name>" & my encodeXML(name of em as string)) & "</wxp:name>
"
end try
set retVal to (retVal & " <wxp:ID>" & address of em as string) & "</wxp:ID>
"
set retVal to retVal & " <wxp:type>" & theType & "</wxp:type>
"
set retVal to retVal & " </wxp:attendee>
"
end if
return retVal
end tell
end writeAttendee
Can some on please look into it and let me know what i am doing wrong here.
Thanks In Advance.
Ravi Kishore.
The line set em to email address of theAttendee lies outside the tell application "Microsoft Outlook" block and so AppleScript does not understand the term email address. Move this statement inside a tell application "Microsoft Outlook" block and you should be okay.

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

Resources