Adobe Illustrator: placed items how to serve?

Hi all!

How i can take an informations about placed iems?
I need a link status:

modified, missng or normal.

:rolleyes:

Hm… no ansvers…

i try to do


	tell application id "com.adobe.illustrator"
open fileAlias
			try
				set placedItemList to every placed item of current document
			end try
			set placedCount to count of placedItemList
			log "placedCount “ " & placedCount
			
			repeat with i from 1 to placedCount
				set placedItem to item i of placedItemList
					set placedName to name of placedItem
				try
					set placedItemPosixPath to file path of placedItem
					set linkedItemsError to false
				on error
					log "Linked file ---------->" & placedName & "<-------------- Don't exist!"
					set linkedItemsError to true
				end try
			end repeat
end tell

Where on error take path of placed item i set trigger to true.

may have a more elegant solution?

Hi, ilexxey. What is it you are ultimately trying to do? The method you used to trap the error is mostly correct, although you don’t necessarily need to save the trigger value; the fact that the error occurred at all is a trigger.

tell application "Adobe Illustrator"'s document 1 to repeat with index from (count placed items) to 1 by -1
	try
		placed item index's file path
	on error --doesn't exist
		--do whatever with this information
	end try
end repeat

Hi, Mark!

I make trigger for skip export file as EPS (if the error occurred) and save report about broken links in text file.
If all links present, i save bottom layer as PDF with all items whose need to rasterise, then convert to TIFF.

Thanks, i like your solution :slight_smile:

It may be someone will be interesting


(*
This script is part of the materials accompanying the books 'AppleScriptObjC Explored' and 'Everyday AppleScriptObjC'.
 The collection is copyright 2010-14 Shane Stanley, <sstanley@myriad-com.com.au>
 and may not be copied without consent.
 The code may be copied and modified freely by purchasers.
 Created by Shane Stanley. v2.0
<sstanley@myriad-com.com.au>.
'AppleScriptObjC Explored' <http://www.macosxautomation.com/applescript/apps/>

###””””””””””””””””””””””””””””””””””””””””””””””
# timer(pAction)          Calculate and Log Execution Time
#
# Ver 1.0 2016-02-21
#
# REF: The base ASObjC code was provided by Shane Stanley
###””””””””””””””””””””””””””””””””””””””””””””””

*)

use AppleScript version "2.4.1"
use scripting additions
use framework "Foundation"

global gTimerStartDate

property outputFolder : missing value
property tempFolder : missing value
property vectorFilePosixPaths : {}
property vectorTypeIDsList : {"com.adobe.illustrator.ai-image", "com.adobe.encapsulated-postscript"}
property adobePdfID : {"com.adobe.pdf"}
property rasterTypeIDsList : {"com.adobe.photoshop-image", "dyn.ah62d4rv4ge81a65c", "public.tiff", "public.png"}

property myTitle : "Make Production EPS files from Illustrator layouts"

property currentTIFFResolution : missing value

on run
	set tempFolder to missing value
	set vectorFilePosixPaths to {}
	
	my timer:"start"
	
	set theFile to POSIX path of (choose file with prompt "Choose a file to convert in to the EPS-production:")
	set outputFolder to POSIX path of (choose folder with prompt "Выберите путь для финальных файлов:")
	
	--set my outputFolder to my setOutputFolder:choosenFolder
	
	log "outputFolder “ " & outputFolder
	
	set tempResolution to display dialog "Укажите разрешение для финальных файлов:" default answer ""
	set currentTIFFResolution to text returned of tempResolution as text
	
	set theResult to my setTempFolder:outputFolder --> Назначаем временный фолдер
	if theResult is false then
		-- my logDialog_("Ошибка", "невозможно создать временный фолдер!")
		activate me
		display alert "Невозможно создать временный фолдер!" & return & return & "Возможно нет права на запись в фолдер" & return & return & outputFolder
		return
	end if
	(its collectFromItem:(POSIX path of (theFile)) vectorFiles:vectorFilePosixPaths) --> Сортировка файлов по типу
	set theResult to my exportTempFiles()
	if theResult is false then
		my closeIllustratorDocument_()
		my deleteItemAt:tempFolder --> Удаление временного фолдера
		return
	end if
	set theResult to my exportTiffFiles()
	if theResult is false then
		my closeIllustratorDocument_()
		my deleteItemAt:tempFolder --> Удаление временного фолдера
		return
	end if
	set theResult to my saveProdFiles()
	if theResult is false then
		my closeIllustratorDocument_()
		my deleteItemAt:tempFolder --> Удаление временного фолдера
		return
	end if
	my deleteItemAt:tempFolder --> Удаление временного фолдера
	my timer:"stop"
	activate me
	display dialog "Your files has been converted to EPS" & return & "\n\n¢ " & ((current date) as text) & "\n¢ EXECUTION TIME: " & (round (-(gTimerStartDate's timeIntervalSinceNow())) * 1000) / 1000.0
	return
end run

on open droppeditems
	set tempFolder to missing value
	set vectorFilePosixPaths to {}
	my timer:"start"
	set outputFolder to POSIX path of (choose folder with prompt "Выберите путь для финальных файлов:")
	set tempResolution to display dialog "Укажите разрешение для финальных файлов:" default answer ""
	set currentTIFFResolution to text returned of tempResolution as text
	set theResult to my setTempFolder:outputFolder --> Назначаем временный фолдер
	if theResult is false then
		activate me
		display alert "Невозможно создать временный фолдер!" & return & "Возможно нет права на запись в фолдер “" & return & return & outputFolder
		return
	end if
	repeat with aFile in (droppeditems as list)
		(its collectFromItem:(POSIX path of (aFile)) vectorFiles:vectorFilePosixPaths)
	end repeat
	
	set theResult to my exportTempFiles()
	if theResult is false then
		my closeIllustratorDocument_()
		my deleteItemAt:tempFolder --> Удаление временного фолдера
		return
	end if
	set theResult to my exportTiffFiles()
	if theResult is false then
		my closeIllustratorDocument_()
		my deleteItemAt:tempFolder --> Удаление временного фолдера
		return
	end if
	set theResult to my saveProdFiles()
	if theResult is false then
		my closeIllustratorDocument_()
		my deleteItemAt:tempFolder --> Удаление временного фолдера
		return
	end if
	my deleteItemAt:tempFolder --> Удаление временного фолдера
	my timer:"stop"
	activate me
	display dialog "Your files has been converted to EPS" & return & "\n\n¢ " & ((current date) as text) & "\n¢ EXECUTION TIME: " & (round (-(gTimerStartDate's timeIntervalSinceNow())) * 1000) / 1000.0
	return
end open
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Save temporary PDF and Ai files / Сохранение временных PDF и Ai файлов
on exportTempFiles()
	(*
tell application "Finder"
		try
			set visible of process "Adobe Illustrator CC 2015" to false
		end try
	end tell
*)
	repeat with aFile in vectorFilePosixPaths
		set fileAlias to (((aFile as text) as POSIX file) as alias) --> Alias for Illustrator
		
		--------------------------------------------------------
		--> определение имени, расширения и прочих компонентов
		--------------------------------------------------------
		set trimmedName to (my setTrimmedName:aFile) as text
		
		set pdfName to trimmedName & ".pdf"
		set aiName to trimmedName & ".ai"
		set pdfName to my addPathComponent_(tempFolder, pdfName)
		set aiName to my addPathComponent_(tempFolder, aiName)
		set pdfTempName to (my convertToHFS:pdfName)
		set aiTempName to (my convertToHFS:aiName)
		
		tell application id "com.adobe.illustrator"
			set user interaction level to never interact
			with timeout of 1200 seconds
				try #1 - Error open file
					open fileAlias with options {create artboard with artwork bounding box:true} without dialogs
				on error the error_message number the error_number
					tell me --------> Чтобы запускал скрипт, а не другая программа
						activate
						display dialog "#1  \"exportTempFiles\" can't open Illustrator file" & return & the error_number & ". " & the error_message ¬
							buttons {"OK"} default button 1 with icon stop with title myTitle
					end tell
					return false
				end try
			end timeout
			
			set docRef to the current document
			set docName to name of docRef
			
			-- set placedRasterList to (every raster item of docRef whose embedded is true)
			-- set placedRasterList to (every raster item of docRef)
			try
				set placedItemList to every placed item of docRef
			end try
			set placedCount to count of placedItemList
			log "placedCount “ " & placedCount
			
			repeat with i from 1 to placedCount
				set placedItem to item i of placedItemList
					set placedName to name of placedItem
				try
					set placedItemPosixPath to file path of placedItem
					set linkedItemsError to false
				on error
					log "Linked file ---------->" & placedName & "<-------------- Don't exist!"
					set linkedItemsError to true
				end try
			end repeat
			
			if linkedItemsError is false then
				tell docRef
					set layersCount to (count of layers)
					set visible of every layer to false
					set visible of layer layersCount to true
					set locked of layer layersCount to false
					
					with timeout of 1200 seconds --> Сохранение нижнего слоя со всем мусором в PDF для дальнейшего растрирования в Фотожабе
						try #2 “ Error save PDF file
							tell application id "com.adobe.illustrator"
								--save current document in file pdfTempName as pdf ¬
								--with options {class:PDF save options, compatibility:Acrobat 6, preserve editability:false, color compression:automatic JPEG maximum, color destination id:color dest working cmyk, color downsampling:300, color downsampling threshold:450, color resample:bicubic downsample, grayscale compression:automatic JPEG maximum, grayscale downsampling:300, grayscale downsampling threshold:450, grayscale resample:bicubic downsample}
								save current document in file pdfTempName as pdf ¬
									with options {class:PDF save options, compatibility:Acrobat 6, preserve editability:false, color compression:automatic JPEG maximum, color destination id:color dest profile, color profile id:include all profiles, color downsampling:300, color downsampling threshold:450, color resample:bicubic downsample, grayscale compression:automatic JPEG maximum, grayscale downsampling:300, grayscale downsampling threshold:450, grayscale resample:bicubic downsample}
							end tell
						on error the error_message number the error_number
							tell me
								activate
								display dialog "#2 \"exportTempFiles\" can't save PDF temp file " & return & the error_number & ". " & the error_message ¬
									buttons {"OK"} default button 1 with icon stop with title myTitle
							end tell
							return false
						end try
					end timeout
					delete layer layersCount of docRef -------> Удаление нижнего слоя со всем мусором, что там есть
					tell docRef
						set visible of every layer to true
					end tell
					with timeout of 1200 seconds --> Сохранение остальных слоев в формате EPS
						try #3 -- Error save EPS file
							tell application id "com.adobe.illustrator"
								save current document in file aiTempName as eps with options {class:EPS save options, compatibility:Illustrator 10}
							end tell
						on error the error_message number the error_number
							tell me
								activate
								display dialog "#3 \"exportTempFiles\" can't save EPS file " & return & the error_number & ". " & the error_message ¬
									buttons {"OK"} default button 1 with icon stop with title myTitle
							end tell
							return false
						end try
					end timeout
				end tell --> tell docRef
			else
				log "ERROR in placed items"
			end if
			close current document saving no
		end tell
	end repeat
	return true
end exportTempFiles
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Сохранение нижнего слоя верстки в формате TIFF CMYK
on exportTiffFiles()
	set filesList to my listFolder:tempFolder
	try
		repeat with aFile in filesList
			set fileExtension to (my extFromPath:aFile) as text
			if fileExtension is "pdf" as text then
				
				set trimmedName to (my setTrimmedName:aFile) as text
				set fileToOpen to (my convertToHFS:aFile)
				set tiffFileName to trimmedName & ".tif"
				set posixFileName to my addPathComponent_(outputFolder, tiffFileName)
				set fileToSave to (my convertToHFS:posixFileName)
				
				tell application id "com.adobe.photoshop"
					set display dialogs to never
					purge all caches
					
					with timeout of 1800 seconds
						try #1
							open file fileToOpen as PDF with options {class:PDF open options, mode:CMYK, resolution:currentTIFFResolution, use antialias:true, crop page:bleed box, suppress warnings:true}
							--open file fileToOpen as PDF with options {class:PDF open options, mode:RGB, resolution:currentTIFFResolution, use antialias:true, crop page:bleed box, suppress warnings:true}
						on error the error_message number the error_number
							tell me
								activate
								display dialog "#1 \"exportTiffFiles\" “ can't open PDF file " & return & the error_number & ". " & the error_message ¬
									buttons {"OK"} default button 1 with icon stop with title myTitle
							end tell
						end try
					end timeout
					
					set docRef to the current document
					flatten docRef
					
					if (mode of docRef is CMYK) then
						try
							convert docRef to profile "Working CMYK" intent relative colorimetric
						end try
					end if
					
					if (mode of docRef is not CMYK) then
						change mode docRef to CMYK
					end if
					
					with timeout of 1200 seconds
						save current document in file fileToSave as TIFF with options {class:TIFF save options, embed color profile:false, image compression:none, save layers:false, save alpha channels:false}
					end timeout
					
					close current document saving no -- закрытие документа
				end tell
			end if
		end repeat
	on error the error_message number the error_number
		tell me
			activate
			display dialog "Error in exportTiffFiles “ Photoshop Step: " & the error_number & ". " & the error_message ¬
				buttons {"OK"} default button 1 with icon stop with title myTitle
		end tell
		-- my deleteItemAt:tempFolder --> Удаление временного фолдера
		tell application id "com.adobe.photoshop"
			try
				close current document saving no -- закрытие документа
			end try
		end tell
		return false
	end try
	-- my deleteItemAt:tempFolder --> Удаление временного фолдера
	return true
end exportTiffFiles
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Сохранение финальных файлов
on saveProdFiles()
	set tiffFilesList to {}
	set illustratorFilesList to {}
	
	--> Подсчет количества Tiff и Ai файлов в папках
	set aiTempList to my listFolder:tempFolder
	set tiffTempList to my listFolder:outputFolder
	
	-- обрабатываем иллюстраторовские файлы	
	repeat with aFile in aiTempList
		set fileExtension to (my extFromPath:aFile) as text
		set fileName to (my nameFromPath:aFile) as text
		-----------------------------------------------------
		--> Выбор EPS файлов во временном каталоге
		if fileExtension is "eps" as text then
			set end of illustratorFilesList to aFile --------------------------------> Добавляем полный POSIX путь к файлу в конец списка EPS файлов
		end if
		-----------------------------------------------------
	end repeat
	
	repeat with aFile in tiffTempList
		set fileExtension to (my extFromPath:aFile) as text
		set fileName to (my nameFromPath:aFile) as text
		
		if fileExtension is "tif" as text then
			set end of tiffFilesList to aFile ----------------------------------------> Добавляем полный POSIX путь к файлу в конец списка TIFF файлов
		end if
	end repeat
	
	repeat with iFile in illustratorFilesList
		
		set aiOpenName to (((iFile as text) as POSIX file) as alias) --> Alias for Illustrator
		
		set cutAiName to (my setTrimmedName:iFile) as text
		set aiName to (my nameFromPath:iFile) as text
		
		set posixAiName to my addPathComponent_(outputFolder, aiName)
		set epsSaveName to (my convertToHFS:posixAiName)
		
		repeat with tFile in tiffFilesList --> Ишем имя TIFF-файла, совпадающее с именем иллюстраторовского файла			
			set cutTiffName to (my setTrimmedName:tFile) as text
			if cutTiffName as text = cutAiName as text then
				set placedFile to (((tFile as text) as POSIX file) as alias)
				exit repeat
			end if
		end repeat
		
		tell application id "com.adobe.illustrator"
			set user interaction level to never interact
			with timeout of 1200 seconds
				open aiOpenName without dialogs
			end timeout
			
			set docRef to the current document
			set docName to name of docRef as text
			set docHeight to height of docRef
			set docWidth to width of docRef
			
			tell docRef
				set ruler origin to {0.0, 0.0}
			end tell
			
			set properties of every layer of docRef to {visible:true}
			tell docRef
				try
					convert to paths (every text frame)
					embed placed items
				end try
			end tell
			
			try
				-- по умолчанию импортируем файл с координатами 0 по X и 0 по Y (без блидов)
				set {_xcoord, _ycoord} to {0 as real, 0 as real}
				make new layer at the end in docRef with properties {name:"Background"}
				
				with timeout of 1200 seconds
					set placedRef to make new placed item at the end in current document with properties {file path:placedFile, position:{_xcoord, docHeight + _ycoord}}
				end timeout
				
				set itemHight to height of placedRef
				set itemWidth to width of placedRef
				
				-- проверяем размер импортируемого файла, если он больше размера документа, то устанавливаем блиды в 5 мм
				(*				
if (itemHight - docHeight) > (2.83465 * 3) and (itemWidth - docWidth) > (2.83465 * 3) then
					set bleedSize to (itemHight - docHeight) as integer
					set position of placedRef to {-bleedSize / 2, itemHight - (bleedSize / 2)}
				end if
*)
				set bleedSize to (itemHight - docHeight) as integer
				set position of placedRef to {-bleedSize / 2, itemHight - (bleedSize / 2)}
				
				set properties of every layer of docRef to {locked:true}
				set properties of every layer of docRef to {locked:false}
				
				with timeout of 1200 seconds
					-- save docRef in prodFileName as eps with options {class:EPS save options, compatibility:Illustrator 10}
					-- save docRef in prodFileName as Illustrator with options {compressed:true, PDF compatible:false, compatibility:Illustrator 13}
					try
						save docRef in epsSaveName as eps with options {class:EPS save options, compatibility:Illustrator 10, embed linked files:true}
					end try
				end timeout
				close current document saving no
			on error the error_message number the error_number
				tell me
					activate
					display dialog "Error in  save production Illustrator Step: " & the error_number & ". " & the error_message ¬
						buttons {"OK"} default button 1 with icon stop with title myTitle
				end tell
				exit repeat
				return false
			end try
		end tell
	end repeat
	return true
end saveProdFiles

on dspinfomsg(infomsg)
	tell me
		activate
		display dialog infomsg buttons {"OK"} default button 1 with icon stop with title myTitle
	end tell
end dspinfomsg
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Подсчет и сортировка выбранных файлов/фолдеров с разделением на векторные и растровые типы файлов
on collectFromItem:posixPath vectorFiles:vectorPaths
	--> make an NSURL so we can get info
	set anNSURL to current application's class "NSURL"'s fileURLWithPath:posixPath
	--> things we want to know about the file
	set requiredKeys to {current application's NSURLIsDirectoryKey, current application's NSURLIsPackageKey, current application's NSURLTypeIdentifierKey}
	--> get the values as a dictionary
	set infoDict to anNSURL's resourceValuesForKeys:requiredKeys |error|:(missing value)
	--> check if it's a folder
	if (infoDict's objectForKey:(current application's NSURLIsDirectoryKey)) as boolean and (infoDict's objectForKey:(current application's NSURLIsPackageKey)) as boolean is false then
		-->> get contents of folder
		set fileManager to current application's NSFileManager's defaultManager()
		set theFiles to fileManager's contentsOfDirectoryAtURL:anNSURL includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)
		-->> loop through, passing files to this handler
		set fileCount to theFiles's |count|()
		repeat with i from 1 to fileCount
			set onePath to (theFiles's objectAtIndex:(i - 1))'s |path|()
			(my collectFromItem:onePath vectorFiles:vectorPaths)
		end repeat
	else --> a file
		-->> we only need to check the UTI
		set this_typeID to (infoDict's objectForKey:(current application's NSURLTypeIdentifierKey))
		-->> workspace is used for UTIs
		set theWorkspace to current application's NSWorkspace's sharedWorkspace()
		repeat with aUTI in vectorTypeIDsList
			if (theWorkspace's |type|:this_typeID conformsToType:(aUTI as text)) as boolean then
				copy posixPath to end of vectorFilePosixPaths
				exit repeat
			end if
		end repeat
	end if
end collectFromItem:vectorFiles:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Назначение временного фолдера
on setTempFolder:posixPath
	set fileManager to current application's NSFileManager's defaultManager()
	set posixPath to current application's NSString's stringWithString:posixPath --> POSIX path to file for work and modify.
	
	-- set my tempFolder to posixPath's stringByAppendingPathComponent:"Temp" --> Назначаем имя для создания временного фолдера
	set my tempFolder to my addPathComponent_(posixPath, "Temp")
	
	if fileManager's fileExistsAtPath:tempFolder then --> if tempFolder already exists
		log "-----------------> tempFolder already exists <“------------------"
		try #1-1.
			set my tempFolder to current application's NSString's stringWithString:tempFolder
		on error the error_message number the error_number
			tell me
				activate
				display dialog "ERROR 1-1. In the Module \"setTempFolder\":" & return & "Error number: " & error_number & return & error_message as text
			end tell
			return false
		end try
	else --> if tempFolder does not exists
		log "-----------------> tempFolder does not exists <“------------------"
		try #1-2.
			fileManager's createDirectoryAtPath:tempFolder withIntermediateDirectories:true attributes:(missing value) |error|:(missing value)
			if fileManager's fileExistsAtPath:tempFolder then
			else
				return false
			end if
		on error the error_message number the error_number
			tell me
				activate
				display dialog "ERROR 1-2. In the Module \"tempFolder\":" & return & "Error number: " & error_number & return & error_message as text
			end tell
			return false
		end try
		set my tempFolder to current application's NSString's stringWithString:tempFolder
	end if
	log "tempFolder “------------------>" & tempFolder
	-- my logDialog_("tempFolder --------->", tempFolder)
	return true
end setTempFolder:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Назначение фолдера для сохранения финальных файлов
on setOutputFolder:posixPath
	repeat with aFile in vectorFilePosixPaths
		set theFolder to my getPathComponents_(aFile, 5)
	end repeat
end setOutputFolder:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Get file name from path
on nameFromPath:thePath
	-- log "Path from file “ Start"
	set thePath to current application's NSString's stringWithString:thePath
	return thePath's lastPathComponent()
end nameFromPath:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Get file extensions from path
on extFromPath:thePath
	-- log "Path from file “ Start"
	set thePath to current application's NSString's stringWithString:thePath
	return thePath's pathExtension()
end extFromPath:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Получение имени файла без расширения
on setTrimmedName:posixPath
	set posixPath to current application's NSString's stringWithString:posixPath
	set fileName to (its nameFromPath:posixPath) as text -- Имя файла с расширением
	set fileExtension to (its extFromPath:posixPath) as text -- Расширение файла
	set the trimmedName to text 1 thru -((length of fileExtension) + 2) of the fileName
	return trimmedName
end setTrimmedName:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Получение компонентов имени файла
on partsOfName:posixFilePath
	set posixPath to current application's NSString's stringWithString:posixPath
	set fileName to (its nameFromPath:posixFilePath) as text -- Имя файла с расширением
	set fileExtension to (its extFromPath:posixFilePath) as text -- Расширение файла
	set the trimmedName to (text 1 thru -((length of fileExtension) + 2) of the fileName) as text
	return {fileName, fileExtension, trimmedName}
end partsOfName:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Add component to path/Добавление компонента к существующему пути
on addPathComponent_(posixPath, lastComponent)
	set fileManager to current application's NSFileManager's defaultManager()
	set posixPath to current application's NSString's stringWithString:posixPath
	set fullPosixPath to posixPath's stringByAppendingPathComponent:lastComponent
	-- set hfsFileName to (((fullPath as text) as POSIX file) as text)
	--log "addPathComponent: hfsFileName “ " & hfsFileName
	return fullPosixPath
end addPathComponent_
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Convert POSIX path to HFS
on convertToHFS:posixPath
	set hfsPath to (((posixPath as text) as POSIX file) as text)
	return hfsPath
end convertToHFS:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Delete an selected item (file/folder)
on deleteItemAt:posixPath --> deletes immediately, does not put in Trash; use carefully!!!
	set theNSFileManager to current application's NSFileManager's defaultManager()
	set theResult to theNSFileManager's removeItemAtPath:posixPath |error|:(missing value)
	return (theResult as integer = 1)
end deleteItemAt:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> List items in selected folder/Получение списка файлов в выбранном фолдере и пути к ним
on listFolder:folderPosixPath --> где posixPath “ полный POSIX путь к фолдеру
	set filesPosixPaths to {}
	set theNSFileManager to current application's NSFileManager's defaultManager()
	set theNames to (theNSFileManager's contentsOfDirectoryAtPath:folderPosixPath |error|:(missing value)) as list
	repeat with i from 1 to count of theNames
		if item i of theNames does not start with "." then
			set theName to item i of theNames ----------------------------------------------> Тут получаем только имя файла с расширением
			set filePosixPath to my addPathComponent_(folderPosixPath, theName) -----> Добавляем имя файла к пути к фолдеру
			set end of filesPosixPaths to filePosixPath ----------------------------------------> Добавляем полный POSIX путь к файлу в конец списка файлов
		end if
	end repeat
	return filesPosixPaths
end listFolder:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> List items in selected folder/Получение списка файлов в выбранном фолдере и пути к ним
on checkPlacedItems:posixPath --> где posixPath “ полный POSIX путь к файлу
	set fileManager to current application's NSFileManager's defaultManager()
	set posixPath to current application's NSString's stringWithString:posixPath
	
	if (fileManager's fileExistsAtPath:posixPath) then
		log "Linked file exists"
		return true
	else
		log "Linked file does not exists"
		return false
	end if
end checkPlacedItems:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
--> Timer
on timer:pAction
	if (pAction = "start") then
		set gTimerStartDate to current application's NSDate's |date|()
		log "START: " & ((current date) as text)
	else
		log pAction & ":  \n    ¢ " & ((current date) as text) & "\n    ¢ EXECUTION TIME: " & (round (-(gTimerStartDate's timeIntervalSinceNow())) * 1000) / 1000.0
		return
	end if
end timer:
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
on closeIllustratorDocument_()
	tell application id "com.adobe.illustrator"
		try
			close current document saving no -- закрытие документа
		end try
	end tell
	return
end closeIllustratorDocument_
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-- display log as alert/dialog
on logDialog_(firstEntry, secondEntry)
	tell me
		activate
		display dialog firstEntry & " “ " & secondEntry
	end tell
end logDialog_
-------------------------------------------------------------------------------------------------------------