Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

importing text with a 'variable'

Featured Replies

I have a project where I need to import information from text files that contains lines and lines of 3 comma separated values. I used this thread to get most of the way there. Link to earlier thread

but then the customer said that the filename of the text file needed to be included as well. After much thought I came up with this solution below. Feel free to comment on any clumsy code, or potential pitfalls.

The script looks at an "in" folder, and works its way through the list of text files available. The text in the file is written to temporary file and at the end of each line the filename is added (to make a fourth field). The applescript launches a Filemaker script to import the text. Then the applescript wipes clean the temporary file and goes on to the next text file.

What I still need is a more graceful way to keep the applescript from moving ahead before the Filemaker script is finished importing. The delay 15 is clumsy. Any suggestions?

set watchedFolder to (path to desktop as Unicode text) & "watched folder:"

set importFolder to (watchedFolder & "New Manifests:") as alias

set doneFolder to (watchedFolder & "Imported Manifests:") as alias



set picFolder to importFolder as Unicode text



tell application "Finder"

	try

		set picList to every file of folder picFolder as alias list

	on error number -1700

		set picList to first file of folder picFolder as alias as list

	end try

end tell



repeat with eachFile in picList

	-- picList contains aliases, so need for 'file' before 'eachFile'.

	set myData to (read eachFile as text using delimiter return)

	set howMany to count of items in myData

	set fileName to name of (info for eachFile)

	try

		copy (open for access file (watchedFolder & "ImportMeNext.txt") with write permission) to fileRef

		repeat with i from 1 to howMany

			write (item i of myData & "," & fileName & return) to fileRef

		end repeat

		close access fileRef

	on error

		close access fileRef

	end try

	

	tell application "FileMaker Pro"

		activate

		do script "Import Script"

	end tell

	delay 15

	

	tell application "Finder"

		activate

		---

		try

			move eachFile to folder doneFolder

		on error

			set name of eachFile to ("1" & fileName)

			move eachFile to folder doneFolder

			

		end try

		try

			set myFile to (open for access file (watchedFolder & "ImportMeNext.txt") with write permission)

			set eof myFile to 0

			close access myFile

		on error

			close access myFile

		end try

		

	end tell

	

end repeat

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.